不和谐的丰富嵌入按钮

Leg*_*ion 3 python discord.py

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

在此处输入图片说明

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

Suj*_*jit 5

在这里,您可以...我能够创建一个命令来编辑响应点击的嵌入内容:

程序:

import discord
from discord.ext import commands

TOKEN=""

client=commands.Bot(command_prefix=".")

@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,'\u23ee')
    await client.add_reaction(message,'\u25c0')
    await client.add_reaction(message,'\u25b6')
    await client.add_reaction(message,'\u23ed')

    i=0
    emoji=''

    while True:
        if emoji=='\u23ee':
            i=0
            await client.edit_message(message,embed=pages[i])
        if emoji=='\u25c0':
            if i>0:
                i-=1
                await client.edit_message(message,embed=pages[i])
        if emoji=='\u25b6':
            if i<2:
                i+=1
                await client.edit_message(message,embed=pages[i])
        if emoji=='\u23ed':
            i=2
            await client.edit_message(message,embed=pages[i])

        res=await client.wait_for_reaction(message=message,timeout=30)
        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)

client.run(TOKEN)
Run Code Online (Sandbox Code Playgroud)

屏幕截图:

在此处输入图片说明

类似于'\ u23ee'的字符串是它们各自表情符号的Unicode。

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

希望您能明白。


Suj*_*jit 5

我已经写了这个问题的答案,但是该答案适用于旧版本discord.py. 看到这个问题获得了大量的浏览量,我决定为最新版本的discord.py.

\n

程序:

\n
@client.command()\nasync def embedpages(ctx):\n    page1 = discord.Embed (\n        title = \'Page 1/3\',\n        description = \'Description\',\n        colour = discord.Colour.orange()\n    )\n    page2 = discord.Embed (\n        title = \'Page 2/3\',\n        description = \'Description\',\n        colour = discord.Colour.orange()\n    )\n    page3 = discord.Embed (\n        title = \'Page 3/3\',\n        description = \'Description\',\n        colour = discord.Colour.orange()\n    )\n    \n    pages = [page1, page2, page3]\n\n    message = await ctx.send(embed = page1)\n    await message.add_reaction(\'\xe2\x8f\xae\')\n    await message.add_reaction(\'\xe2\x97\x80\')\n    await message.add_reaction(\'\xe2\x96\xb6\')\n    await message.add_reaction(\'\xe2\x8f\xad\')\n\n    def check(reaction, user):\n        return user == ctx.author\n\n    i = 0\n    reaction = None\n\n    while True:\n        if str(reaction) == \'\xe2\x8f\xae\':\n            i = 0\n            await message.edit(embed = pages[i])\n        elif str(reaction) == \'\xe2\x97\x80\':\n            if i > 0:\n                i -= 1\n                await message.edit(embed = pages[i])\n        elif str(reaction) == \'\xe2\x96\xb6\':\n            if i < 2:\n                i += 1\n                await message.edit(embed = pages[i])\n        elif str(reaction) == \'\xe2\x8f\xad\':\n            i = 2\n            await message.edit(embed = pages[i])\n        \n        try:\n            reaction, user = await client.wait_for(\'reaction_add\', timeout = 30.0, check = check)\n            await message.remove_reaction(reaction, user)\n        except:\n            break\n\n    await message.clear_reactions()\n
Run Code Online (Sandbox Code Playgroud)\n

截屏:

\n

在此输入图像描述

\n

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

\n

我希望你能明白。

\n