4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

discord.pyでmessage.contentが取得されない

Last updated at Posted at 2022-06-10

経緯

Discordのアップデートによって、ボイスチャンネルにそれ専用のテキストチャンネルが追加されていた。
このテキストチャンネル、現行のPython Package Indexに含まれているバージョンのdiscord.pyのバージョン1.7.3において、見かけ上ではボイスチャンネルとされているため、

await send(content=None, *, tts=False, embed=None, ...)

を用いたテキストチャンネルへのメッセージ送信ができない。
これをどうにかする。

この問題の原因

  • discord.pyのバージョン
  • DiscordのIntents設定のし忘れ

この二つ。

解決方法

discord.pyのバージョンを上げる

まずこれ。
そもそも現行バージョンではVoiceChannelのオブジェクト自体にsend()メソッドがない
バージョンアップせざるを得ない。

python3 -m pip install git+https://github.com/Rapptz/discord.py

Gitからそのままインストール。
旧バージョンが見つかれば勝手に削除される。

Intentsの設定

DEVELOPER PORTAL

DiscordのDEVELOPER PORTALのアプリケーションを開き、Botの箇所を開く。
image.png
ここのPrivileged Gateway Intentsを好みに設定する。

スクリプト

TOKEN = 'Your token here'
client = discord.Client(intents=discord.Intents.all())

# process here

client.run(TOKEN)

バージョンアップに伴ってdiscord.Client()の引数にIntentsを指定する。

 
この二つの操作をすればmessage.contentが空じゃなくなる。

さいごに

エラーはこれで出なくなるうえに機能するようになるが、discord.pyのバージョンを無理やり上げたうえで実行しているため、正直やめるべき。(Pypiにあるv1.7.3を使うべき)
ただ公式のBotでもない身内間で使う限りは構わないだろうと思ってしまう。
公式の見解では、そもそもこのイベントのみを待機するBotは今後サポートしなくなるようだ。discord.extを用いたコマンドのBotを全面サポートする方向性に変えていきたいらしい。

4
0
0

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
4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?