【问题标题】:custom embeds not showing up自定义嵌入未显示
【发布时间】:2020-09-11 13:49:10
【问题描述】:

我正在制作机器人,它需要一个命令后跟一个输出嵌入的字符串

我的想法是让它遵循以下准则:al_emb "Title Here" "Description Here"

到目前为止我的代码:

@bot.command()
async def emb(c,embed):
    #first = c.content.split()[1]
    #second = c.content.split()[2]
    first = c.content
    #embed = embed.Embed(title=first, description=second, color=0x00ff00)
    embed = embed.Embed(title=first, color=0x00ff00)
    await c.send(embed=embed)

我没有得到任何输出

非常感谢任何帮助

【问题讨论】:

  • 机器人是否发送空白消息?
  • 它没有发送任何东西,但是如果我执行简单的“al_emb”,我会收到 commands.MissingRequiredArgument 错误
  • 如果它没有用你提供的代码发送任何东西,你应该检查你的机器人在你的服务器中是否有“嵌入权限”
  • 机器人有管理员,所以它应该有所有人员和频道覆盖

标签: python python-3.x discord discord.py


【解决方案1】:

您的代码的问题是 ctx 没有属性内容。试试这个功能:

@commands.command()
async def emb(self, ctx, *, args): # "self" assuming this command is in a cog
    embed = discord.Embed(title=args, color=0x00ff00)
    await ctx.send(embed=embed)

【讨论】:

  • 我的代码在一个 cog 仅供参考,我的目标是设置命令:imgur.com/a/xdEsFyR 当我使用您提供的代码时,我收到“命令不存在”错误,当commands.CommandNotFound 我也收到错误时,我的错误处理程序会输出这个:Undefined variable 'discord'
  • 只需将import discord 放在文件顶部,或者在@DanA 之前进行嵌入
  • @DanA 如果你得到commands.CommandNotFound,那么你一定调用了一个不存在的命令。该错误不能由命令本身引起。
  • imgur.com/a/tqS5qcp 我正在使用命令al_emb test 并没有得到任何输出
  • 首先,函数应该不缩进一层。它们不是__init__ 的一部分。其次,第一个函数使用@bot.command,而第二个函数使用@commands.command。取消缩进后,确保它们都是@commands.command
【解决方案2】:

您可以在协程的签名中包含两个参数:

class MyCog(commands.Cog):
    @commands.command()
    async def emb(self, ctx, title, description):
        embed = discord.Embed(title=title, description=description, color=0x00ff00)
        await ctx.send(embed=embed)

【讨论】:

  • 我想我会提到我在 cog 中使用此命令,并且使用该代码机器人不会输出任何内容
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-03-30
  • 2011-10-02
  • 2021-09-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-05
相关资源
最近更新 更多