Enable intents for discord.py bot

馋奶兔 提交于 2021-02-13 17:37:07

问题


Im making a discord bot, and every time it joins a new server, the bot sends me the server info and an invite. However, when I've tested this, it always shows one member which is itself. I have both presence and members intents enabled in the discord developer portal, but it still isn't working.

I then changed some code to Guild.fetch_members() to which I received the error:

discord.ext.commands.errors.CommandInvokeError:
Command raised an exception:
ClientException:
Intents.members must be enabled to use this.

As I said before, on the discord developers website member intents are enabled and I have had this code before without this issue.

When I had this code working before, it was using 1.5.x (I cant remember exactly) and now its using 1.6.0, so something in the new update may prevent this from working, but this is unusual to me, so how can I resolve this issue?


回答1:


intents were introduced in 1.5.0 so I don't think they were working before, but answering your question

intents = discord.Intents.default()
intents.members = True

bot = commands.Bot(..., intents=intents)

Also remember to enable privileged member intents in the developer portal

How to enable privigeled intents




回答2:


Somebody posted this as an answer but deleted it, and it actually worked.

intents = discord.Intents.default()
intents.members = True

client = commands.Bot(command_prefix=prefix, intents=intents)


来源:https://stackoverflow.com/questions/65935181/enable-intents-for-discord-py-bot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!