LoginSignup
1
1

More than 3 years have passed since last update.

discord.pyでmembersが取れるようにする

Posted at

discord.pyではguild.membersでメンバー一覧を取得できます

#メンバー一覧を表示
mes = '\n'.join([m.name for m in message.guild.members])
await message.channel.send(mes)

しかし、これでは自分自身のbot以外が表示されないこともあります。

discord.pyのバージョンアップに伴い、
メンバーの一覧を取得するにはオプションが必要になりました。

具体的にdiscord.Client()時に以下のようにするといいです。

# 接続に必要なオブジェクトを生成
intents = discord.Intents.default()  # デフォルトのIntentsオブジェクトを生成
intents.typing = False  # typingを受け取らないように
intents.members = True  # membersを受け取る
client = discord.Client(intents=intents)

typingは「メッセージを入力中です」を受け取らない設定です
多分、普通はいらないはずです

1
1
3

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
1
1