0
0

Discordで"アクシオ"という言葉が表示された場合にマウスポインタを指定した場所に自動で移動させてみる

Last updated at Posted at 2024-02-25

Discordのチャットを監視して、"アクシオ"という言葉が表示された場合にマウスポインタを指定した場所に移動させる。
”アクシオ”と聞いてすぐに意味がわかる人は友達になれる気がする。

その前に以下のライブラリをインストールしておきます。
pyautoguiとdiscord.pyの2つのライブラリを使用します。

pip install pyautogui discord.py

Discord部屋を監視するbotアカウントの作り方はググってください。

~試行錯誤中~
どうやってもDIscord部屋に置いたbotが"アクシオ"を認識してくれない。
"Message Content Intent" を有効にしてるんだが。。。。
誰か教えて(´;ω;`)

[2024-02-25 23:57:45] [WARNING ] discord.ext.commands.bot: Privileged message content intent is missing, commands may not work as expected.
[2024-02-25 23:57:45] [INFO    ] discord.client: logging in using static token
[2024-02-25 23:57:46] [INFO    ] discord.gateway: Shard ID None has connected to Gateway
intentsの設定において、特権が正しく有効化されていないことを示しています。Discord.py v1.7.0以降では、特権の有効化が必要とされています。
先程のコードで intents.messages を True にしていましたが、恐らくその影響で特権が有効化されなかった可能性があります。
以下のように修正してみてください。
import discord
from discord.ext import commands
import pyautogui

# Discord Botのトークンを設定
TOKEN = 'YOUR_DISCORD_BOT_TOKEN'

# ボットのプレフィックスを設定
intents = discord.Intents.all()
bot = commands.Bot(command_prefix='!', intents=intents)

# 移動させたい座標を指定
destination_coordinates = (500, 500)

# 監視したいトピックを指定
topic = 'buy'

@bot.event
async def on_ready():
    print(f'Logged in as {bot.user.name}')

@bot.event
async def on_message(message):
    if message.author.bot:
        return  # ボットのメッセージは無視

    # 指定したトピックで始まる場合
    if message.content.startswith(topic):
        # マウスポインタを指定した座標に移動
        pyautogui.moveTo(*destination_coordinates)
        print('Mouse moved to the specified coordinates.')

# Discordボットを起動
bot.run(TOKEN)
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0