'RawReactionActionEvent'对象没有属性'author添加事件冷却时间的问题

时间:2020-08-14 18:05:26

标签: discord.py discord.py-rewrite

我正在尝试为discord.py中的on_raw_reaction_add事件添加冷却时间。我正在尝试通过使用冷却时间映射来做到这一点。结果应该是限制此消息的次数

embed.description = f"It looks like you're joining us on a newly registered account. Verification requires accounts to be atleast a day old so please stick around and try again at {test_time.time().strftime(format)}."
如果

如果在添加反应时未达到帐户使用期限,则会发送给用户,这应该是冷却开始之前的一个反应。

我得到的错误是'RawReactionActionEvent' object has no attribute 'author不知道为什么会这样。

这是我正在使用的完整代码:

@commands.Cog.listener()
async def on_raw_reaction_add(self, payload):  # Will be dispatched every time a user adds a reaction to a message the bot can se
    general = self.bot.get_channel(701547632354525249)
    introductions = self.bot.get_channel(705068046267580566)
    botroom = self.bot.get_channel(706610280032894996)
    if not payload.guild_id:
        # In this case, the reaction was added in a DM channel with the bot
        return 
    guild = self.bot.get_guild(payload.guild_id)
    author = guild.get_member(payload.user_id)
    bucket = self._cd.get_bucket(payload)
    retry_after = bucket.update_rate_limit()
    seconds = bucket.update_rate_limit()
    seconds = round(seconds, 2)
    hours, remainder = divmod(int(seconds), 3600)
    minutes, seconds = divmod(remainder, 60)
    if retry_after:
        verification_error = f"You can do that again in **{minutes}m {seconds}s**."
        embed = discord.Embed(title="You have already verified.", description=verification_error, colour=discord.Colour(0xff8100))
        await message.channel.send(embed=embed)
        pass
    
    if payload.message_id != 743841858727444550:
        return
    else:
        guild = self.bot.get_guild(payload.guild_id)  # You need the guild to get the member who reacted
        member = guild.get_member(payload.user_id)  # Now you have the key part, the member who should receive the role
    
        if payload.emoji.id != 743077610115956816:
            reaction = payload.emoji.id
            role = discord.utils.get(guild.roles, name="Members")
            newbies = discord.utils.get(guild.roles, name="Newbies")
            restricted_role = discord.utils.get(guild.roles, name="Restricted")
            role = discord.Object(743840972068356116)  # Pass the role's ID here
        else:
            return
        
        if restricted_role in member.roles:
            return
    
        
        if member.created_at + dt.timedelta(days=30) <= dt.datetime.today():
            await member.add_roles(role, reason='New member verified')  # Finally add the role to the member
            await member.add_roles(newbies, reason='New member verified')  # Finally add the role to the member
            welcome = f'Welcome {member.mention}! feel free to get started with adding some <#706648361196978177>'
            intros = f'Hey {member.mention}! now that you\'re a member of our group, maybe you\'d like to tell us a bit about yourself. Tell us an interesting fact about yourself and so on... As always keep it sensible and fun.'
            await general.send(welcome)
            sent = await introductions.send(intros)
            await asyncio.sleep(900)
            await sent.delete()
        else:
            format = '%I:%M%p'
            member1 = member.created_at.strftime("%I:%M%p")
            dt3 =  dt.datetime.strptime(member1, format)
            test_time = dt3 + dt.timedelta(minutes = 1500)
            embed = discord.Embed(colour=discord.Color(0x7289DA))
            embed.title = f"Hey there {member.display_name}!"
            embed.description = f"It looks like you're joining us on a newly registered account. Verification requires accounts to be atleast a day old so please stick around and try again at {test_time.time().strftime(format)}."
            await member.send(embed=embed)

我们将不胜感激。

1 个答案:

答案 0 :(得分:0)

在您的@ client.command语句下,只需添加 @ commands.cooldown(1,30,命令.BucketType.user) 此示例将为单个用户提供30秒的冷却时间,供1次使用。您也可以将BuckType配置为通道和服务器。