简体   繁体   中英

Discord.py Embeded messages not sending from else statement

I'm trying to make a command that takes the user's display name and adds it to a list, "registering" them for an event, but whenever I call the command, it doesn't send the confirmation message of a successful registration. But, if I've already registered, it sends that message telling me I already registered.

Here is my code:

@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)

It seems to only be the embedded messages under the second "else" statements that aren't working as I was able to print the contents of the list (fireteam) that the user's names are stored in to the console on a successful registration and my name was on that list, so it's going meeting the criteria to get to that else statement and run that code. Along with that, if I do "^register" a second time, I get the "you already registered" message to pop up, so it's recording my info, it's just not sending the embedded messages.

for person in fireteam:
    name = ''.join(person)
    embed.add_field(value= name, inline= False) # this causes error

add_field cant be called without a name param

an alternative way would be

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM