Discord.py:加入和离开消息不起作用

时间:2021-06-06 13:24:32

标签: python discord.py bots

为人们加入和离开我的服务器创建加入和离开消息功能,但它似乎不起作用,代码看起来完全没问题。没有错误。有什么我遗漏的吗?

# are any of these causing the issues?
intents = discord.Intents.default()

intents.members = True

client = discord.Client(intents=intents)

client = commands.Bot(command_prefix='-')

client.remove_command('help')

client.load_extension('cogs.commands')
# ---------


@client.event
async def on_member_join(member):

    await client.wait_until_ready()

    channel = client.get_channel(850882992708124702)

    await channel.send(f"Welcome {member}!")


@client.event
async def on_member_remove(member):

    channel = client.get_channel(850883012103241748)

    await channel.send(f"Goodbye {member}!")

2 个答案:

答案 0 :(得分:1)

问题是你覆盖了你的客户:

client = discord.Client(intents=intents)

client = commands.Bot(command_prefix='-')

用它来解决这个问题:

client = commands.Bot(command_prefix='-', intents=intents)

答案 1 :(得分:0)

问题是你用了太多client 对于这个问题,这是你的原始代码:

intents = discord.Intents.default()
intents.members = True
client = discord.Client(intents=intents)
client = commands.Bot(command_prefix='-')
client.remove_command('help')
client.load_extension('cogs.commands')

要修复它,您必须包含 command_prefix='-'client = discord.Client(intents=intents) 所以这是如何修复它的代码:

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

client = commands.Bot(command_prefix='-', intents=intents)

client.remove_command('help')
client.load_extension('cogs.commands')