python - Discord 丰富的嵌入按钮

标签 python discord.py

我制作了一些 discord.py 机器人,但我遇到了一个令人惊讶的机器人。它称为 IdleRPG,使用带有按钮的丰富嵌入消息。这是一张照片(请注意菜单底部的按钮):

enter image description here

我已经尝试联系开发人员并一直在网上搜索,但似乎无法找到他们是如何做到的。有谁知道有关如何创建它们的任何资源?请提供链接。

最佳答案

更新:请检查this回答最新版本的 discord.py


给你......我能够创建一个命令来编辑响应点击的嵌入:

程序:

@client.command()
async def embedpages():
    page1 = discord.Embed (
        title = 'Page 1/3',
        description = 'Description',
        colour = discord.Colour.orange()
    )
    page2 = discord.Embed (
        title = 'Page 2/3',
        description = 'Description',
        colour = discord.Colour.orange()
    )
    page3 = discord.Embed (
        title = 'Page 3/3',
        description = 'Description',
        colour = discord.Colour.orange()
    )

    pages = [page1, page2, page3]

    message = await client.say(embed = page1)

    await client.add_reaction(message, '⏮')
    await client.add_reaction(message, '◀')
    await client.add_reaction(message, '▶')
    await client.add_reaction(message, '⏭')

    i = 0
    emoji = ''

    while True:
        if emoji == '⏮':
            i = 0
            await client.edit_message(message, embed = pages[i])
        elif emoji == '◀':
            if i > 0:
                i -= 1
                await client.edit_message(message, embed = pages[i])
        elif emoji == '▶':
            if i < 2:
                i += 1
                await client.edit_message(message, embed = pages[i])
        elif emoji == '⏭':
            i = 2
            await client.edit_message(message, embed=pages[i])
        
        res = await client.wait_for_reaction(message = message, timeout = 30.0)
        if res == None:
            break
        if str(res[1]) != '<Bots name goes here>':  #Example: 'MyBot#1111'
            emoji = str(res[0].emoji)
            await client.remove_reaction(message, res[0].emoji, res[1])

    await client.clear_reactions(message)

截图:

enter image description here

要接受页码,您必须为该表情符号创建一个 if 语句并使用 wait_for_message() 函数。然后您必须检查页码是否有效并相应地更改 i 的值。

我希望你明白这一点。

关于python - Discord 丰富的嵌入按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55075157/

相关文章:

python : upload my own files into my drive using Pydrive library

python - django 模型类 __init__ 中的 keyerror

python - Discord Bot 无法离开语音 channel 'NoneType' 对象没有属性 'disconnect'

ffmpeg - 让 Discord 机器人从直接 url 播放声音

python - 将数据框中的负值转换为正值 - Python

python - 基维,Python : Update Label on_file_drop

Python字典检查键是否存在

discord.py - 我经常收到 HTTP 错误 403 Forbidden using discord.py and ytdl

python - (Python : discord. py)错误 : Could not build wheels for multidict, 使用 PEP 517 且无法直接安装的 yarl

python - 远程服务器上的子进程