不和谐的丰富嵌入按钮 [英] Discord rich embed buttons

查看:42
本文介绍了不和谐的丰富嵌入按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

解决方案

更新:请检查

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

希望您能明白.

I made a few discord.py bots, but I came across one which was surprising. It's called IdleRPG and uses rich embed messages with buttons. Here's a pic (note the buttons at the bottom of the menu):

I've tried contacting the developer and been searching the net but can't seem to find how they did it. Does anyone know of any resources on how to create them? Please provide links.

解决方案

Update: Please check this answer for the latest version of discord.py.


Here you go... I was able to create a command that edits the embed on reaction clicks:

Program:

@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)

Screenshot:

For accepting a page number you'll have to create an if statement for that emoji and use the wait_for_message() function. Then you'll have to check whether the page number is valid and change the value of i accordingly.

I hope you get the idea.

这篇关于不和谐的丰富嵌入按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆