繁体   English   中英

如何获取对我嵌入 discord 做出反应的人的角色和用户名?

[英]how to get the roles and username of the person who reacted to my embed in discord?

    suggestEmbed.add_field(name='Ticket ID: ', value = f'{uniqueID}', inline=False)    
    message = await channel.send(embed = suggestEmbed)
    await message.add_reaction('✅')
    await message.add_reaction('❌')
 
    sendEmbed.set_author(name = f'suggested by {ctx.message.author}', icon_url = f'{ctx.author.avatar_url}')
    sendEmbed.timestamp = datetime.utcnow()
    
    def check (reaction, user):
        return not user.bot and message == reaction.message
    
    try:
        reaction, user = await bot.wait_for('reaction_add',check=check,timeout=604800)
        while reaction.message == message:
            if str(reaction.emoji) == "✅":
                await ctx.send("🚀🚀🚀 Yay! Your suggestion has been approved, We thank you for your valuable time!")
                await channel.send(f'suggestion of {ctx.message.author}, with ID: {uniqueID} has been approved, this post will no longer be active')
                return
            if str(reaction.emoji) == "❌":
                await ctx.send("🙇‍♀️🙇‍♀️ Sorry! Your suggestion has not been approved, We thank you for your valuable time!")
                message1 = await ctx.send(embed = sendEmbed)
                await channel.send(f'suggestion of {ctx.message.author}, with ID: {uniqueID} has not been approved, this post will no longer be active')
                return
    except asyncio.TimeoutError:
        await ctx.send("Your suggestion was timed out. Please try again!")
        return

我想知道对我的嵌入做出反应的人的角色/用户名。 (使用 dicord.py 制作)。 有没有办法可以使用 ctx 访问它? 或任何其他我不知道的方式。

由于您从bot.wait_for获取user ,因此您可以使用以下两者之一简单地访问用户名:

username =  user.display_name
#or
username = user.name

以及您可以使用以下方式访问的角色:

roles = user.roles #user.roles returns a list because the user can have multiply roles.
#Attention! This will raise an error if the reaction was in a dmchannel

参考

暂无
暂无

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

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