Discord.Py嵌入命令

2024-10-01 09:42:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在制作一个有各种命令的机器人。其中一个命令应该是嵌入。例如,您在何处说出命令、标题和描述。但是机器人只能用一个单词作为标题,一个单词作为描述。我需要帮助,我的代码在下面使用。(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)

Tags: 命令send标题titlechannelnot机器人embed
2条回答

这里有一个想法:

@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的建议进行操作

资料来源:

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

相关问题 更多 >