如何在discord.py中加入/离开消息

时间:2018-11-29 04:02:24

标签: python bots discord discord.py

@bot.event
async def on_member_join(member):
    fmt = "{} has joined"
    await bot.send_message(member, fmt.format(member, member.server))

@bot.event
async def on_member_remove(member):
    fmt = '{} has left'
    await bot.send_message(member, fmt.format(member, member.server))

这是我的代码,我想加入而不留下消息

channel = member.server.get_channel("CHANNEL_ID")

此代码,以便所有使用此漫游器的服务器都可以使用加入/离开消息。 如果输入此代码,则只能对特定服务器使用加入和保留消息。

1 个答案:

答案 0 :(得分:0)

Discord 频道 ID 专用于一个频道,您不能在多个频道/服务器上使用相同的 ID。
您可以尝试为欢迎频道使用单一名称:

channel = discord.utils.get(ctx.guild.channels, id=modlog)

或者使用数据库,其中每个服务器都可以为欢迎频道保存自己的频道 ID,您可以像这样使用:

channel = discord.utils.get(ctx.guild.channels, id=modlog)