![](/img/trans.png)
[英]Sending messages from only 1 channel in Discord (discord.py bot)
[英]Discord.py Embeded messages not sending from else statement
我正在嘗試創建一個命令,該命令采用用戶的顯示名稱並將其添加到列表中,為事件“注冊”他們,但是每當我調用該命令時,它都不會發送成功注冊的確認消息。 但是,如果我已經注冊,它會發送消息告訴我我已經注冊。
這是我的代碼:
@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)的內容打印出來name 在該列表中,因此它將滿足到達該 else 語句並運行該代碼的條件。 除此之外,如果我第二次執行“^注冊”,我會彈出“您已經注冊”的消息,因此它正在記錄我的信息,只是不發送嵌入的消息。
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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.