【问题标题】:Discord.py on member update does not work会员更新上的 Discord.py 不起作用
【发布时间】:2021-03-05 23:32:48
【问题描述】:

我正在开发一个不和谐的机器人,我想在用户角色发生变化时进行记录。我尝试了下面的代码,这才刚刚开始。

TOKEN = ""

client = discord.Client()

@client.event
async def on_ready():
    print(f'{client.user} has connected to Discord!')

@client.event
async def on_message(message):
    print(message)

@client.event
async def on_member_update(before, after):
    print(before)
    print(after)

client.run(TOKEN)

当我在频道中输入消息时,它会将消息打印到 python 控制台,但是,当我在同一个公会中为自己添加角色时,它不会打印任何内容。

注意:我在 Discord 开发者门户中启用了 presence intentserver member intent

【问题讨论】:

  • 存在,成员意图应该在不和谐开发者门户中启用,也可以通过代码启用。
  • 之前是什么,之后是什么?

标签: discord discord.py discord.py-rewrite


【解决方案1】:

您应该从您的代码中激活它,例如:

intents = discord.Intents.default()
intents.members = True
intents.presences = True
client= discord.Client(intents=intents)

reference for more information

【讨论】:

    【解决方案2】:

    您的意图应该在门户网站和代码本身上都启用。

    这是你在代码中的做法。

    intents = discord.Intents().all()
    client = discord.Client(intents=intents)
    

    并根据docs of on_memebr_update

    This requires Intents.members to be enabled.

    这就是它不起作用的原因。

    【讨论】:

      猜你喜欢
      • 2020-07-12
      • 2021-04-30
      • 2021-03-24
      • 2018-10-04
      • 2021-02-25
      • 2021-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多