为discord.py bot启用意图 [英] Enable intents for discord.py bot

查看:59
本文介绍了为discord.py bot启用意图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个不和谐的bot,每次它加入新服务器时,该bot都会向我发送服务器信息和邀请.但是,当我对此进行测试时,它总是显示一个本身就是成员.我在不和谐的开发人员门户中已同时启用状态和成员意图,但仍然无法正常工作.

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.

然后我将一些代码更改为收到错误的 Guild.fetch_members():

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.

当我之前使用此代码时,它使用的是1.5.x(我记不清了),现在使用的是1.6.0,因此新更新中的某些内容可能会阻止此代码的工作,但这对我来说是不寻常的,那么我该如何解决这个问题?

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.5.0 中引入的,因此我认为它们以前没有作用,但可以回答您的问题

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

如何启用特权意图

这篇关于为discord.py bot启用意图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆