Discord bot commands not working on reaction roles (Discord PY)

妖精的绣舞 提交于 2020-06-23 14:02:06

问题


When i go to execute my script it shows me this error. Not sure what it is but please help me!

Error shown This was the error shown when i ran my bot. I have no clue but i was trying to set up reaction roles and this popped up

        @bot.event()
TypeError: event() missing 1 required positional argument: 'coro'

Part of script with error This is the part of the script the error directing me to telling me it was there!

@bot.event()

    async def on_raw_reaction_add(payload):
        message_id = payload.message_id
        if message_id == 710694229554233344:
            guild_id = payload.guild_id
            guild = discord.utils.find(lambda g : g.id == guild_id, bot.guilds)

            if payload.emoji.name == 'thumbsup':
                role = discord.utils.get(guild.roles, name="cpp")
            elif payload.emoji.name == 'wink':
                role = discord.utils.get(guild.roles, name="csharp")
            else:
                role = discord.utils.get(guild.roles, name=payload.emoji.name)

            if role is not None:
                print(role.name)

    @bot.event
    async def on_raw_reaction_remove(payload):
        pass

Full script if needed this is the full code if needed to look at the whole thing for bugs!

import discord
from discord.ext import commands

bot = commands.Bot(command_prefix='~')

@bot.event
async def on_ready():
    await bot.change_presence(status=discord.Status.online)
    print('The bot {0.user} has successfully been turned online!'.format(bot))

@bot.command()
@commands.has_permissions(manage_messages=True)
async def clear(ctx, amount=2):
        await ctx.channel.purge(limit=amount)

@bot.command()
@commands.has_permissions(kick_members=True)
async def kick(ctx, member : discord.Member, *, reason=None):
    await member.kick(reason=reason)
    await ctx.channel.send(f"{Member} has been kicked")

@bot.command()
@commands.has_permissions(ban_members=True)
async def ban(ctx, member : discord.Member, *, reason=None):
    await member.ban(reason=reason)
    await ctx.channel.send(f"{user.name} has been banned")
    await ctx.member.send(f"{ctx.guild.name} is the server you have been banned from!")

@bot.command()
async def latency(ctx):
    await ctx.send(f"Latency of bot is {bot.latency}|ms")

@bot.command()
async def unban(ctx, *, member):
    banned_users = await ctx.guilds.bans()
    member_name, member_discriminator = member.split('#')

    for banned_entry in banned_users:
        user = banned_entry.user

        if (user.name, user.discriminator) == (member_name, member_discriminator):
            await ctx.guild.unban(user)
            await ctx.send(f"Unbanned {user.name}#{user.discriminator}!")
            return

@bot.command()
async def test(ctx, *, member):
    await ctx.send(f"Unbanned {user.name}.")

@bot.event()
async def on_raw_reaction_add(payload):
    message_id = payload.message_id
    if message_id == 710694229554233344:
        guild_id = payload.guild_id
        guild = discord.utils.find(lambda g : g.id == guild_id, bot.guilds)

        if payload.emoji.name == 'thumbsup':
            role = discord.utils.get(guild.roles, name="cpp")
        elif payload.emoji.name == 'wink':
            role = discord.utils.get(guild.roles, name="csharp")
        else:
            role = discord.utils.get(guild.roles, name=payload.emoji.name)

        if role is not None:
            print(role.name)

@bot.event
async def on_raw_reaction_remove(payload):
    pass

bot.run('<Token>')

回答1:


You need to remove the parenthesis after event. It's @bot.event, just like your remove reaction event. Please note that you still use them on the commands, @bot.command()



来源:https://stackoverflow.com/questions/61811448/discord-bot-commands-not-working-on-reaction-roles-discord-py

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!