带按钮的命令 - Discord.py

时间:2021-07-17 16:44:08

标签: python discord discord.py bots

在我的 Discord 机器人中,我通过反应创建了帮助命令。但最近我听说了“按钮”。许多开发人员建议我使用按钮而不是反应。有人知道如何修改我的代码以使消息保持不变吗? 顺便说一句,这是我当前的代码:

@client.command()
async def help(ctx):
    contents = [
    discord.Embed(title='Utilities commands',description=
f'''
text 1    
''',colour=0xF00C0C),
    discord.Embed(title='Moderation commands',description=
f'''
text 2
''',colour=0xF00C0C),
    discord.Embed(title='Fun commands',description=
f'''
text 3
''',colour=0xF00C0C),
    discord.Embed(title='Coding commands',description=
f'''
text 4
''',colour=0xF00C0C),
    discord.Embed(title='Bot\'s info | ID: 856643485340139580',description=
'''
text 5
''',colour=0xF00C0C)
]
    pages = 5
    cur_page = 1
    message = await ctx.send(embed=contents[cur_page - 1])

    await message.add_reaction("◀️")
    await message.add_reaction("▶️")

    def check(reaction, user):
        return user == ctx.author and str(reaction.emoji) in ["◀️", "▶️"]

    while True:
        try:
            reaction, user = await client.wait_for("reaction_add", check=check)

            if str(reaction.emoji) == "▶️" and cur_page != pages:
                cur_page += 1
                await message.edit(embed=contents[cur_page - 1])
                await message.remove_reaction(reaction, user)

            elif str(reaction.emoji) == "◀️" and cur_page > 1:
                cur_page -= 1
                await message.edit(embed=contents[cur_page - 1])
                await message.remove_reaction(reaction, user)

            else:
                await message.remove_reaction(reaction, user)

        except:
            break

感谢任何形式的帮助!

1 个答案:

答案 0 :(得分:1)

discord.py 还没有实现 v2.0 中的组件“按钮”。
通过在官方 Discord 服务器中注册为测试人员,即可进行 Beta 测试。

或者,有一个用于组件的 3rd 方库,但根本不推荐使用,因为它具有破坏性功能和猴子补丁,其中大部分将在 discord.py 的未来更新中停止工作。

我建议在 2.0 和文档的正式发布之前不要使用按钮,除非您觉得自己有足够的能力来测试 2.0。

https://discord.gg/dpy 是 Discord 服务器。