I want the bot to give role to users if they mentions three people in a specific channel, I want to do this with 2 channels and role for both channels are different, code:
@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)
This doesn't give any error also It doesn't work. I can't find any error.
Your error i think is with the emoji itself make sure it is in the guild i edited it a bit.
@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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.