【发布时间】:2020-09-16 10:11:40
【问题描述】:
我一直在编写一个机器人,它会在用户加入时欢迎他们,但它似乎不起作用。
async def on_member_join(member):
channel = member.channel
await channel.send(f'{member} has arrived')
【问题讨论】:
标签: python discord discord.py
我一直在编写一个机器人,它会在用户加入时欢迎他们,但它似乎不起作用。
async def on_member_join(member):
channel = member.channel
await channel.send(f'{member} has arrived')
【问题讨论】:
标签: python discord discord.py
您还没有指定哪里您要将消息发送到的频道,并且discord.Member 没有名为channel 的属性。
您必须通过其 ID 获取频道,如下所示:
async def on_member_join(member):
channel = bot.get_channel(112233445566778899) # replace id with the welcome channel's id
await channel.send(f"{member} has arrived!")
如果你愿意,你也可以通过它的名字来获取它:
async def on_member_join(member):
channel = discord.utils.get(member.guild.text_channels, name="welcome")
await channel.send(f"{member} has arrived!")
参考资料:
【讨论】:
@client.event
async def on_member_join(member):
for channel in member.guild.channels:
if str(channel) == "member-log":
await channel.send(f"""Welcome {member.mention}!""")
这也可能有帮助。在这里,我们正在检查频道名称是否为member-log,然后向该频道发送欢迎消息。
【讨论】: