我有say
命令,可以正常工作,并在其中提供一条消息作为答复。但是,我想更改代码以支持自定义嵌入消息。
基本上,我的问题是:如何使我的say
命令回复消息或自定义嵌入正文消息?
我的say
命令
@commands.command(name='say', aliases=['repeat', 'talk'])
@commands.has_permissions(manage_messages=True)
async def _say(self, ctx, *, message):
await ctx.send(message, ctx)
我希望我的命令能够执行的操作是...
示例:
-say {embed=discord.Embed(title="Test", description="Embed Example")
embed.set_author(name="Author", url="https://authorlink.com", icon_url="https://authoricon.com")
embed.set_thumbnail(url="https://thumbnail.png")
embed.add_field(name="Field 1", value="Field test 1", inline=True)
embed.add_field(name="Field 2", value="Field test 2", inline=False)
embed.set_footer(text=ctx.guild.name)
await ctx.send(embed=embed)}
有人知道如何制作代码以发送自定义嵌入正文消息吗?我了解Embed及其制作方式。现在,我只希望我的命令能够说出自定义嵌入和自定义消息。我希望我的主意是有道理的。
(这样,我无法自定义整个嵌入,而只能自定义代码中提供的字段的值。我正在寻找一种使之完全自定义的方法,如果可能的话,并与一个命令合并仅用于嵌入和普通邮件)_
@commands.command(name="sayembed")
@commands.has_permissions(manage_messages=True)
async def _saye(self, ctx, *, message):
embedsay = discord.Embed(color=ctx.author.color, timestamp=ctx.message.created_at)
embedsay.set_author(name="Message from:", icon_url=ctx.author.avatar_url)
embedsay.add_field(name=ctx.message.author, value=str(message))
embedsay.set_thumbnail(url=ctx.author.avatar_url)
embedsay.set_footer(text=ctx.guild.name)
await ctx.send(embed=embedsay)
答案 0 :(得分:0)
因为您的say命令很好,但是如果要添加嵌入,则需要embed = discord.Embed()
示例:
import datetime
import discord
from discord import Embed
from discord.ext import commands
client = commands.Bot(command_prefix='PREFIX')
@client.command()
async def embed(ctx):
embed = discord.Embed(
title='This is a title! you can customise this!',
description='This is a description!',
colour=discord.Color.green(),
timestamp=datetime.datetime.now()
).add_field(
name='This is non inlined field 1!',
value='This is a value!',
inline=False
).add_field(
name='This is a non inlined field 2!',
value='This is a value!',
inline=False
).add_field(
name='This is a inlined field 1!',
value='This is a value!',
inline=True
).add_field(
name='This is a inlined field 2!',
value='This is a value!',
inline=True
).set_footer(
text='This is a footer!',
icon_url='https://cdn.discordapp.com/avatars/694446165197979670/eb946325b85f913abdec645d0c14b98a.webp?size=1024'
).set_image(
url='https://cdn.discordapp.com/avatars/694446165197979670/eb946325b85f913abdec645d0c14b98a.webp?size=1024'
).set_thumbnail(
url='https://cdn.discordapp.com/avatars/694446165197979670/eb946325b85f913abdec645d0c14b98a.webp?size=1024'
)
await ctx.send(embed=embed)
您可以完全自定义嵌入,但是如果您未在add_field上包含标题或值,则会引发错误(当然您可以将它们串起来)。
如果您要发送特殊消息,可以执行
@client.command()
async def say(ctx, member: discord.Member, *, message):
embed = discord.Embed(
title=message,
description=f"From: {ctx.author}",
colour=discord.Color.green()
)
await member.send(embed=embed)
答案 1 :(得分:0)
我知道这已经解决了,但是除非每个参数的消息都改变(例如kick命令),否则不必将其包含在命令本身中,只需使用:
<varname> = discord.Embed(title=„title”, description=„description”, color=(use hex codes)
<varname>.add_field(basically the field, im on an iPhone rn and dont want to type it all out)
<varname>.set_footer, .set_thumbnail, etc.
async def say(ctx):
[TAB] ctx.send(embed=<varname>)
答案 2 :(得分:0)
您可以使用此代码记住用 /
拆分标题和描述,否则该命令将不起作用示例命令:!embed title/description
import discord
from discord.ext import commands
import datetime
bot = commands.bot(command_prefix=commands.when_mentioned_or("!"))
@bot.command()
async def embed(ctx, *, content: str):
title, description= content.split('/')
embed = discord.Embed(
title=title,
description=description,
colour=discord.Color.green(),
timestamp=datetime.datetime.now()
)
await ctx.send(embed=embed)
bot.run("your token here")