如果用户在特定频道中提到三个人,我希望该机器人赋予用户角色,我想通过2个频道来做到这一点,并且两个频道的角色都不同, 代码:
@client.event
async def on_message(message):
if message.channel.id == 724969989777522778:
try:
if len(message.mentions) >= 3:
await message.add_reaction(emoji="<a:tick:748476262640779276>")
role = discord.utils.get(message.guild.roles, name="CUSTOM 3pm")
user = message.author
await user.add_roles(role)
#await.message.add_reaction(emoji="<a:zw40:738102925339000873>")
else:
return
except:
return
if message.channel.id == 724970270347100203:
try:
if len(message.mentions) >= 3:
await message.add_reaction(emoji="<a:tick:748476262640779276>")
role = discord.utils.get(message.guild.roles, name="CUSTOM 4pm")
user = message.author
await user.add_roles(role)
#await.message.add_reaction(emoji="<a:zw40:738102925339000873>")
except:
return
await client.process_commands(message)
这也不给出任何错误,也不起作用。我找不到任何错误。
答案 0 :(得分:0)
我认为表情符号本身是您的错误,请确保它在公会中,我对此进行了一点编辑。
@bot.event
async def on_message(message):
if message.channel.id == 724969989777522778 or message.channel.id == 724970270347100203:
if len(message.mentions) >= 3:
role_name = "CUSTOM 3pm" if message.channel.id == 724969989777522778 else "CUSTOM 4pm"
await message.add_reaction(emoji='✅')
role = discord.utils.get(message.guild.roles, name=role_name)
user = message.author
try:
await user.add_roles(role)
except:
print('Already have the role')
await bot.process_commands(message)