Discord.Py 嵌入命令
Discord.Py Embed Command
我正在用各种命令制作一个机器人。其中一个命令应该是制作嵌入。例如你在哪里说命令、标题和描述。但是机器人只能用一个词作为标题,一个词作为描述。我需要帮助,我的代码在下面使用。 (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)
这是一个想法:
@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)
我正在用各种命令制作一个机器人。其中一个命令应该是制作嵌入。例如你在哪里说命令、标题和描述。但是机器人只能用一个词作为标题,一个词作为描述。我需要帮助,我的代码在下面使用。 (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)
这是一个想法:
@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)