繁体   English   中英

Star-Board discord.py 问题

[英]Star-Board discord.py issues

我正在使用 json 文件来存储公会的右舷通道。 这是我的代码:

@client.event
async def on_raw_reaction_add(payload):
    star = await get_star_channels()

    if str(payload.message.guild.id) not in star:
        return

    starchannel = client.get_channel(star[str(payload.message.guild.id)])
    
    

    if payload.emoji == '⭐':
        if str(payload.message.guild.id) not in star:
            return

        if not payload.member.guild_permissions.manage_messages:
            await payload.message.channel.send("You don't have the permissions to star a message")
            return

        if len(payload.message.attachments) > 0:
            embed.set_image(url = payload.message.attachments[0].url)

        embed = discord.Embed(description = f"{payload.message.author}:\n\n{payload.message.content}\n\n**[Jump to message]({payload.message.jump_url})**", color = random.choice(colors_for_embeds1), timestamp = datetime.now())
        embed.set_author(name = f"{payload.member.name} starred a message", icon_url = payload.member.avatar_url)
        
        
        embed.set_footer(text = f"<#{payload.channel.id}>")

        
        await starchannel.send(embed = embed)

我面临的问题是'RawReactionActionEvent' object 没有属性'message''guild'所以我无法获得guild ID where the reaction was added (似乎是这样)。 如果不访问公会 ID,我无法获取star channel ID stored in the JSON file因为key of all the star-channel IDs is the guild ID

你应该使用guild_idmessage_id

以下是 RawReactionActionEvent 的所有属性:

message_id

user_id

channel_id

guild_id

emoji

member仅适用于on_raw_reaction_add

event_type

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM