【问题标题】:Discord.Py Embed CommandDiscord.Py 嵌入命令
【发布时间】:2021-02-28 20:16:21
【问题描述】:

我正在制作一个带有各种命令的机器人。这些命令之一应该是进行嵌入。比如你在哪里说命令、标题和描述。但是机器人只能以一个词作为标题,一个词作为描述。我需要帮助,我的代码在下面使用。 (toob是前缀)

@client.command()
async def makeEmbed(ctx, title: str, description : str):
  if not title:
    await ctx.channel.send("One or more values are missing. Command should look like 'toob makeEmbed (title), (description)'")
  elif not description:
    await ctx.channel.send("One or more values are missing. Command should look like 'toob makeEmbed (title), (description)'")

  
  embed = discord.Embed(title=title, description=description, color=0x72d345)
  await ctx.send(embed=embed)

【问题讨论】:

  • 也许使用toob makeEmbed "title with multiple words" "description with multiple words"。

标签: python discord bots discord.py discord.py-rewrite


【解决方案1】:

这是一个想法:

@client.command()
async def make_embed(ctx, *, content: str):
    title, description = content.split('|')
    embed = discord.Embed(title=title, description=description, color=0x72d345)
    await ctx.send(embed=embed)

调用→toob make_embed Some Title | Some description with a loooot of words

缺点是您需要在消息中添加|, 这是wait_for() 的另一个解决方案:

@client.command()
async def make_embed(ctx):
    def check(message):
        return message.author == ctx.author and message.channel == ctx.channel

    await ctx.send('Waiting for a title')
    title = await client.wait_for('message', check=check)
  
    await ctx.send('Waiting for a description')
    desc = await client.wait_for('message', check=check)

    embed = discord.Embed(title=title.content, description=desc.content, color=0x72d345)
    await ctx.send(embed=embd)

调用↓

>>> toob make_embed
... Waiting for a title
>>> Some title here
... Waiting for a description
>>> Some description here

或者你可以按照ThRnk的建议去做。

来源:

【讨论】:

  • tysm,我回家后试试这个
  • 你试过了吗?
【解决方案2】:
@client.command()
async def test(ctx):
    e = discord.Embed(
    title="Title Of The Embed Here!",
    description="Description Of The Embed Here!",
    color=0xFF0000 #i added hex code of red u can add any like of blue
)
await ctx.send(embed=e)

【讨论】:

    猜你喜欢
    • 2021-06-04
    • 2021-08-09
    • 2020-08-12
    • 2020-09-08
    • 2021-10-20
    • 2019-05-09
    • 2021-01-13
    • 2021-10-15
    • 2021-06-07
    相关资源
    最近更新 更多