问题描述
我正在尝试制作一个适用于我的 discord 服务器网络的验证系统。 这是我希望机器人在您输入“.agree”后执行的操作:
这是我的代码:
@clIEnt.event
async def on_message(message):
verify_channel = clIEnt.get_channel(868120833858621470)
verify_role = get(member.guild.roles,ID='871383440694587462')
if message.content == '.agree' in verify_channel:
await member.add_roles(message.author,verify_role)
await message.send(f'{message.author},thanks!')
奇怪的是我没有收到任何错误消息。它只是不起作用。什么都没有发生。机器人没有添加任何角色,机器人也没有发送任何消息。我试过寻求帮助,但是关于为 Python discord Bots 制作验证系统的指南很少。我也尝试过不同的代码布局方式,但都没有奏效。
注意:我将在整个 discord 服务器网络中使用此机器人和验证系统,这意味着我希望机器人检查频道名称而不是频道 ID。
我怎样才能做到这一点?
解决方法
使用
if message.content == '.agree' and message.channel == verify_channel:
await member.add_roles(message.author,verify_role)
await message.channel.send(f'{message.author},thanks!')
代替
if message.content == '.agree' in verify_channel:
await member.add_roles(message.author,verify_role)
await message.send(f'{message.author},thanks!')
希望这是有道理的:)
支付解锁全部内容
限时5折¥9.9 ¥19.9