Reputation: 93
So I'm trying to put the user input in a list. So the user runs the command, it asks for the user's name and id. Then the user enters their info. and its' stored in a list. Am I doing anything wrong?
@client.command()
async def add(ctx):
await ctx.send("Please ONLY enter your name and student id. (ex. FirstName LastName 000000)")
def check(msg):
return msg.author == ctx.author and msg.channel == ctx.channel
msg = await client.wait_for("message", check=check)
msg_id = msg.content
ids = [""]
ids.append(msg_id)
await ctx.send("Thank you. Your id will be added ASAP.")
Upvotes: 0
Views: 39
Reputation: 3602
If you want to add something to a list, it should be empty to begin with, this makes things much easier. Also, it makes little sense to keep this list inside the command
, instead put it on top of the code, so it doesn't interfere with the code.
Since your list already contains ""
we empty the list ([]
) and define it over the command
.
The complete code:
ids = [] # Empty list
@client.command()
async def add(ctx):
await ctx.send("Please ONLY enter your name and student id. (ex. FirstName LastName 000000)")
def check(msg):
return msg.author == ctx.author and msg.channel == ctx.channel
msg = await client.wait_for("message", check=check)
msg_id = msg.content
ids.append(msg_id)
await ctx.send("Thank you. Your id will be added ASAP.")
print(ids) # Here we check the list
Also make sure your code is indented correctly!
Upvotes: 2