如何在discord.py中让角色on_message? [英] How to make give role on_message in discord.py?

查看:77
本文介绍了如何在discord.py中让角色on_message?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果用户在特定频道中提到三个人,我希望该机器人赋予用户角色,我想通过2个频道来做到这一点,并且两个频道的角色都不同,代码:

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)

这篇关于如何在discord.py中让角色on_message?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆