我正在尝试设置一个启用discord.py的简单bot,但在欢迎新成员时遇到问题。我有以下代码,当一个新成员加入时,bot能够处理Discord发送的默认欢迎消息,但不处理on_member_join()函数中的任何内容。我已经在Discord(网关和成员)中启用了意图,但仍然不明白为什么它不会处理新成员加入。我还测试了一个全新创建的成员,仍然不会触发
import discord
intents = discord.Intents.default()
intents.members = True
client = discord.Client()
@client.event
async def on_ready(): # When ready
print('We have logged in as {0.user}'.format(client))
@client.event
async def on_member_join(member):
print('Someone new!')
await member.send("Welcome")
@client.event
async def on_message(message): # On every message
if message.author == client.user: # Cancel own message
return
if message.content.startswith('?'):
await message.channel.send('Command')
client.run(DISCORD_TOKEN)
这与使用
Client
而不是Bot
无关您创建了
intents
变量,但从未使用过它。您应该将它传递到您的discord.Client()
,而您没有这样做,因此members
意图将始终被禁用这也是为什么你的答案能解决这个问题:因为你实际上是在使用你的意图
使用
discord.Client
或commands.Bot
对这一点没有影响:commands.Bot
没有传递意图也不会做任何事情将您的意图传递到
Client
也会起作用,就像这样可以解决Bot
的问题编辑:参见答案。将以下正确传递的意图(members=True)更改为bot
不确定为什么,但我需要使用bot命令来解决这个问题
增加:
改变
到
我认为这是“完全启用”意图所必需的,但我不完全确定为什么这会纠正这个问题
相关问题 更多 >
编程相关推荐