【问题标题】:Reactions in discord.pydiscord.py 中的反应
【发布时间】:2021-10-22 03:33:43
【问题描述】:

很抱歉,我遇到了问题。我目前正在研究我的 discord.py 机器人,但现在我遇到了问题,如下所示:

我看到我朋友的一个帮助命令,它使用反应在帮助菜单中移动。现在我需要这样的命令。它不是用于帮助命令,而是用于另一个命令,但这不是我要说的。

现在我需要有关如何创建这些“反应管理器”的帮助,如果我可以这样称呼它们... 希望有大神能帮帮我

【问题讨论】:

  • 这能回答你的问题吗? Pagination - Discord.py rewrite
  • 是的,完全一样
  • 但它并没有像我希望的那样回答它
  • 嗯,我找到了我正在寻找的答案。不是通过查看您的链接,而是在谷歌上搜索它

标签: discord.py command bots


【解决方案1】:

当有人添加反应时,您可以简单地编辑您的消息。 这是我发送嵌入所有服务器表情符号及其 ID 的代码:

async def emid(ctx):
"""returns list of server emojis and their id"""
global coun
a = []
b = []
c = []
for emoji in ctx.guild.emojis:
    x = bot.get_emoji(emoji.id)
    a.append('\\' + str(x))
    a.append(str(x))
if len(a) > 21:
    counter = 0
    for i in range(len(a)):
        b.append(a[i])
        if i % 21 == 0 and i != 0:
            counter += 1
            embed = discord.Embed(
                title='Here is the list of server emojis:',
                description='\n'.join(b),
                colour=discord.Colour.from_rgb(r.randint(100, 255), r.randint(100, 255), r.randint(100, 255))
            )
            b = []
            c.append(embed)
    message = await ctx.send(embed=c[0])
    message_id = message.id
    emoji = '⏩'
    emoji1 = '⏪'
    coun = 0
    await message.add_reaction(emoji1)
    await message.add_reaction(emoji)

    @bot.event
    async def on_raw_reaction_add(payload):
        global coun
        if payload.message_id == message_id and payload.emoji.name == '⏩':
            coun += 1
        elif payload.message_id == message_id and payload.emoji.name == '⏪':
            coun -= 1
        try:
            await message.edit(embed=c[coun])
        except:
            pass
else:
    embed = discord.Embed(
        title='Here is the list of server emojis:',
        description='\n'.join(a),
        colour=discord.Colour.from_rgb(r.randint(100, 255), r.randint(100, 255), r.randint(100, 255))
    )
    await ctx.send(embed=embed)

顺便说一句,有一个library 可以创建带有反应的帮助命令:)

【讨论】:

    猜你喜欢
    • 2021-05-13
    • 2022-01-24
    • 2021-08-18
    • 2021-03-04
    • 2021-03-12
    • 2021-03-11
    • 1970-01-01
    • 1970-01-01
    • 2022-08-13
    相关资源
    最近更新 更多