Discord.py 嵌入未发送

Posted

技术标签:

【中文标题】Discord.py 嵌入未发送【英文标题】:Discord.py embed not getting sent 【发布时间】:2021-02-05 01:28:55 【问题描述】:

我只是用 discord.py 编写了一个机器人,但我的帮助命令似乎有问题,因为由于某种原因,我希望发送的嵌入没有显示出来。

这是我的帮助命令代码:

@client.command(aliases=["h"])
async def bothelp(ctx):
   await ctx.send("help command coming soon!")
   embed = discord.Embed(title = "Help for the bot", description = "", color = discord.Colour.purple())
   embed.add_field(name = "Command List", value = "", inline = False)
   embed.add_field(name = "#hello", value = "Replies with a greeting. \nAliases: hey, hi", inline = True)
   embed.add_field(name = "#whois <mention>", value = "Gives the user info of the member mentioned. \nAliases: user, info", inline = True)
   embed.add_field(name = "#clear (number)", value = "Clears the number of messages given by the user. If number is not entered, deletes the most recent message. \nAliases = c \nPermissions = Manage Messages", inline = True)
   embed.add_field(name = "#kick (mention)", value = "Kicks the member mentioned. \nAliases: k \n Permissions: Kick Members", inline = True)
   embed.add_field(name = "#ban (mention)", value = "Bans the member mentioned. \nAliases: b \n Permissions: Ban Members", inline = True)
   embed.add_field(name = "#unban (username with tag)", value = "Unbans the member specified. \nAliases: ub \n Permissions: Ban Members", inline = True)
   embed.set_footer(icon_url = ctx.author.avatar_url, text = f"Requested by ctx.author.name")
   await ctx.send(embed=embed)

但是,嵌入不会发布。我试图找到错误,但我找不到。有人可以帮帮我吗?

谢谢!

【问题讨论】:

【参考方案1】:

字段值不能为无或空字符串,您的第一个字段没有值。为它增加一些价值

以下是修改后的代码:

@client.command(aliases=["h"])
async def bothelp(ctx):
   await ctx.send("help command coming soon!")
   embed = discord.Embed(title = "Help for the bot", description = "", color = discord.Colour.purple())
   embed.add_field(name = "Command List", value = "Here are all commands", inline = False)
   embed.add_field(name = "#hello", value = "Replies with a greeting. \nAliases: hey, hi", inline = True)
   embed.add_field(name = "#whois <mention>", value = "Gives the user info of the member mentioned. \nAliases: user, info", inline = True)
   embed.add_field(name = "#clear (number)", value = "Clears the number of messages given by the user. If number is not entered, deletes the most recent message. \nAliases = c \nPermissions = Manage Messages", inline = True)
   embed.add_field(name = "#kick (mention)", value = "Kicks the member mentioned. \nAliases: k \n Permissions: Kick Members", inline = True)
   embed.add_field(name = "#ban (mention)", value = "Bans the member mentioned. \nAliases: b \n Permissions: Ban Members", inline = True)
   embed.add_field(name = "#unban (username with tag)", value = "Unbans the member specified. \nAliases: ub \n Permissions: Ban Members", inline = True)
   embed.set_footer(icon_url = ctx.author.avatar_url, text = f"Requested by ctx.author.name")
   await ctx.send(embed=embed)

【讨论】:

以上是关于Discord.py 嵌入未发送的主要内容,如果未能解决你的问题,请参考以下文章

Discord.py 嵌入式消息未从 else 语句发送

如何在嵌入 discord.py 中将长字段作为页面发送?

如何在嵌入 discord.py 中使用 markdown 语法发送图像

使用 discord.py 制作一个不和谐的机器人通过嵌入发送图像

使用 discord.py 将已经存在的 json 文件作为嵌入发送

如何使用 discord.py 获取消息