Reputation: 3
I have a bit of a problem with my code below. After calling the command, the list does not update (it doesn't append the discord id of the user I mentioned to the list.) Even though in the print statement that I added after the code executes SHOWS the user's id in the list, but it's not.
cool_people = []
allowed_people = [1232332423472348]
@client.command()
async def makeCool(ctx, member : discord.Member):
for allowed in allowed_people:
if int(ctx.author.id) == allowed:
print("hey u are allowed to use this command! good job")
for coolUser in cool_people:
if coolUser == member.id:
await ctx.send(f'{member.mention} you are already cool!')
elif coolUser != member.id:
print(member.id)
await ctx.send(f"{member.mention} has been added")
cool_people.append(member.id)
print(cool_people)
Upvotes: 0
Views: 650
Reputation: 3426
You should consider using in
instead of looping the entire list. In addition make the list global one method is using client.XXXX
# Made it global
client.cool_people = []
client.allowed_people = [1232332423472348]
@client.command()
async def makeCool(ctx, member : discord.Member):
# skip users not in allowed_people
if ctx.author.id not in client.allowed_people:
return await ctx.send("You are not allowed to use this")
# add user to list if not in cool_pepole
if member.id not in client.cool_people:
client.cool_people.append(member.id)
# code here
Upvotes: 2