【问题标题】:Discord.py Embeded messages not sending from else statementDiscord.py 嵌入式消息未从 else 语句发送
【发布时间】:2021-09-07 08:54:10
【问题描述】:

我正在尝试创建一个命令,该命令获取用户的显示名称并将其添加到列表中,为事件“注册”它们,但是每当我调用该命令时,它都不会发送成功的确认消息登记。但是,如果我已经注册,它会发送消息告诉我我已经注册。

这是我的代码:

@client.command()
async def register(ctx, *, message=''):
    name = ctx.message.author.display_name
    embed = Embed(title='Activity Registration', colour= discord.Colour.blue())
    if len(fireteam) == 6:
        embed.add_field(name='Fireteam Full', value='There is no space left in the fireteam.', inline=False)
    else:
        if name in fireteam:
            embed.add_field(name='You are already registered', value='You cannot register again.', inline=False)
        else:
            fireteam.append(name)
            embed.add_field(name='Successfully Registered', value = name + ' has successfully registered for: **' + message + '**', inline = False)
            embed.add_field(name= 'Current Fireteam:', inline = False)
            for person in fireteam:
                name = ''.join(person)
                embed.add_field(value= name, inline= False)
        embed.set_thumbnail(url= ctx.message.author.avatar_url)
    await ctx.send(embed=embed)

似乎只有第二个“else”语句下的嵌入消息不起作用,因为我能够在成功时将用户名存储到控制台中的列表 (fireteam) 的内容打印出来注册并且我的名字在该列表中,因此它将满足获取该 else 语句并运行该代码的标准。除此之外,如果我第二次执行“^register”,我会弹出“你已经注册”的消息,所以它正在记录我的信息,它只是不发送嵌入的消息。

【问题讨论】:

    标签: python discord.py embed


    【解决方案1】:
    for person in fireteam:
        name = ''.join(person)
        embed.add_field(value= name, inline= False) # this causes error
    

    add_field 不能在没有名称参数的情况下调用

    另一种方法是

    embed.add_field(name = "Current Fireteam", value= "\n".join(fireteam), inline= False)
    

    【讨论】:

      猜你喜欢
      • 2021-02-13
      • 2021-07-10
      • 2021-02-05
      • 2021-07-08
      • 2021-12-25
      • 1970-01-01
      • 2021-08-17
      • 2021-03-08
      • 2020-04-21
      相关资源
      最近更新 更多