Discord.py新成员消息



所以我有这个作为新成员的欢迎信息。

@bot.event
async def on_member_join(member):
channel = bot.get_channel('channel_id')
await channel.send("insert message")

这个在机器人上工作吗?如果加入的人是一个真正的用户,这是否有效?

注意:bot.get_channel()需要int而不是str,如果您已经通过了int,那么请检查您是否已经在开发人员页面和代码中启用了您的bot的意图。

在开发者页面:https://discord.com/developers/applications/{bot_id}/bot在特权网关意图中启用服务器成员意图

在你的代码中:

intents = discord.intents.default()
intents.members = True
bot = commands.bot(command_prefix=prefix, intents=intents)

是的,它会响应机器人。机器人实际上是一个普通的用户,他们只是有一个特殊的状态。

如果你想过滤掉机器人,那么只需要查看成员对象,它包含一个属性,它会告诉你它是否是一个机器人- member.bot.

那么你可以这样写:

@bot.event
async def on_member_join(member):
if not member.bot:
channel = bot.get_channel('channel_id')
await channel.send("insert message")

编辑注:如果你还没有,我建议你做一个测试的不和谐服务器,你可以直接测试它。

要测试人们的连接,只需将其开放给没有帐户的人,并在匿名浏览器窗口中打开服务器邀请。