Discord机器人命令不适用于反应角色(Discord PY)

时间:2020-05-15 03:52:30

标签: python python-3.x discord discord.py-rewrite

当我执行脚本时,会显示此错误。不确定是什么,但是请帮我!

显示的错误:这是我运行机器人时显示的错误。我一无所知,但是我试图设置反应角色,这突然出现了

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

脚本中有错误的部分:这是脚本中的部分,该错误指示我告诉我它在那里!

@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

如有需要,请提供完整脚本:如果需要,请查看完整的代码,以了解漏洞的全部内容!

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 个答案:

答案 0 :(得分:1)

您需要在事件后删除括号。就像您的删除反应事件一样,它是@bot.event。请注意,您仍然在命令@bot.command()

上使用它们