简体   繁体   English

Discord.py 分页

[英]Discord.py pagination

So i want to make embeds be paginated so it can change upon reacting to an emoji i found a project called disputils which made the process a lot easier, but it supports texts and is there anyway i can include pictures in this code(the documentation has no examples or says that pictures can be embedded any help would be appreciated):所以我想使埋件进行分页,因此它可以在反应,表情符号改变我发现了一个项目叫disputils这使得过程轻松了许多,但它支持文本和有反正我可以对这个代码的图片(文件有没有例子或说图片可以嵌入任何帮助将不胜感激):

@bot.command()
async def paginate(ctx):
    embeds = [
        Embed(title="test page 1", description="This is just some test content!", color=0x115599),
        Embed(title="test page 2", description="Nothing interesting here.", color=0x5599ff),
        Embed(title="test page 3", description="Why are you still here?", color=0x191638)
    ]

    paginator = BotEmbedPaginator(ctx, embeds)
    await paginator.run()

i also have tried to use embed.set_image but i get an error positional argument follows keyword argument (<unknown>, line 12) (it highlights the embed.set_image)我也尝试过使用 embed.set_image 但我得到一个错误positional argument follows keyword argument (<unknown>, line 12) (它突出显示了 embed.set_image)

So i want to make embeds be paginated so it can change upon reacting to an emoji i found a project called disputils which made the process a lot easier, but it supports texts and is there anyway i can include pictures in this code(the documentation has no examples or says that pictures can be embedded any help would be appreciated):所以我想让嵌入分页,这样它就可以在对表情符号做出反应时改变我发现了一个名为disputils的项目,这使得这个过程更容易,但它支持文本,无论如何我可以在这段代码中包含图片(文档有没有例子或说图片可以嵌入任何帮助将不胜感激):

@bot.command()
async def paginate(ctx):
    embeds = [
        Embed(title="test page 1", description="This is just some test content!", color=0x115599),
        Embed(title="test page 2", description="Nothing interesting here.", color=0x5599ff),
        Embed(title="test page 3", description="Why are you still here?", color=0x191638)
    ]

    paginator = BotEmbedPaginator(ctx, embeds)
    await paginator.run()

i also have tried to use embed.set_image but i get an error positional argument follows keyword argument (<unknown>, line 12) (it highlights the embed.set_image)我也尝试过使用 embed.set_image 但我得到一个错误positional argument follows keyword argument (<unknown>, line 12) (它突出显示了 embed.set_image)

One thing you can do is to describe the embeds outside the list.您可以做的一件事是描述列表外的嵌入。 It should work brilliantly, as it did for me.它应该工作得很好,就像对我一样。 I included a thumbnail and image option, as I wasn't sure what you meant by "image".我包含了缩略图和图像选项,因为我不确定您所说的“图像”是什么意思。

Make sure you did pip install disputils in the terminal before you try to put the code into your file.在尝试将代码放入文件之前,请确保您在终端中执行了pip install disputils

Here's the code:这是代码:

import discord
from disputils import BotEmbedPaginator, BotConfirmation, BotMultipleChoice


bot = commands.Bot(command_prefix='!')

@bot.command()
async def testing(ctx):
    Embed1 = discord.Embed(title="Title", description="Description", color=0x000000)
    Embed1.set_image(url="https://external-preview.redd.it/mu4xWSMFJroZUimyZY4vvjloaAnmzXTh1O2QI_TFlzc.jpg?width=960&crop=smart&auto=webp&s=e042f61d74a80c4bf3f170b9628c14ef56bac427")
    Embed1.set_thumbnail(url="https://external-preview.redd.it/mu4xWSMFJroZUimyZY4vvjloaAnmzXTh1O2QI_TFlzc.jpg?width=960&crop=smart&auto=webp&s=e042f61d74a80c4bf3f170b9628c14ef56bac427")
    Embed2 = discord.Embed(title="Title", description="Description", color=0x000000)
    Embed2.set_image(url="https://external-preview.redd.it/mu4xWSMFJroZUimyZY4vvjloaAnmzXTh1O2QI_TFlzc.jpg?width=960&crop=smart&auto=webp&s=e042f61d74a80c4bf3f170b9628c14ef56bac427")
    Embed2.set_thumbnail(url="https://external-preview.redd.it/mu4xWSMFJroZUimyZY4vvjloaAnmzXTh1O2QI_TFlzc.jpg?width=960&crop=smart&auto=webp&s=e042f61d74a80c4bf3f170b9628c14ef56bac427")
    Embed3 = discord.Embed(title="Title", description="Description", color=0x000000)
    Embed3.set_image(url="https://external-preview.redd.it/mu4xWSMFJroZUimyZY4vvjloaAnmzXTh1O2QI_TFlzc.jpg?width=960&crop=smart&auto=webp&s=e042f61d74a80c4bf3f170b9628c14ef56bac427")
    Embed3.set_thumbnail(url="https://external-preview.redd.it/mu4xWSMFJroZUimyZY4vvjloaAnmzXTh1O2QI_TFlzc.jpg?width=960&crop=smart&auto=webp&s=e042f61d74a80c4bf3f170b9628c14ef56bac427")
    embeds = [Embed1, Embed2, Embed3]
    paginator = BotEmbedPaginator(ctx, embeds)
    await paginator.run()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM