0
1

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 5 years have passed since last update.

discord.py get_member(user_id) が失敗する時は fetch_member(user_id) を使う

0
Last updated at Posted at 2021-03-27

discord.py でuser_idから Member を取得したかったのですが、
Intentsを設定しているのにも関わらず guild.get_member(user_id) がNoneになってしまうバグに遭遇し、
discord.py get_member 動かない バグ
discord.py get_member not working
などでググっても解決策がヒットせず、自力で解決したため対処法を残しておきます。

Intentsを設定したのに直らない

ググってみると Intentsの設定でmembers=Trueにすれば直りそう だったのですが
まだget_memberがNoneになってしまい、ハマりました。

fetch_member()で解決

いろいろ試行錯誤したところ、
member = guild.get_member(user_id)

member = await guild.fetch_member(user_id)
とすることで無事Memberオブジェクトを取得できました。

Intentsは設定なしでOKなようです。

0
1
2

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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?