Reputation: 3
I know for a fact that the two values in elif user == whitelist:
are the the same and should be triggering the elif statement however the code just passes the elif statement and goes to the else statement. The elif statement does work when I put elif user == "562448514349662208":
however I want the elif statement to be able to read from a variable. I did some testing with other variables and for some reason the elif statement just would not work when I was comparing to a variable
Here is more of my code in case you need more context
whitelist = "562448514349662208"
user = int(message.author.id)
if message.author == bot.user:
content = message.content[3:]
color = discord.Color(value=int("%06x" % random.randint(0, 0xFFFFFF), 16))
embedvar = discord.Embed(description=content, color=color)
await message.delete()
await message.channel.send(embed=embedvar)
if user == whitelist:
content = message.content[3:]
color = discord.Color(value=int("%06x" % random.randint(0, 0xFFFFFF), 16))
embedvar = discord.Embed(description=content, color=color)
await message.channel.send(embed=embedvar)
else:
content = user
color = discord.Color(value=int("%06x" % random.randint(0, 0xFFFFFF), 16))
embedvar = discord.Embed(description=content, color=color)
await message.channel.send(embed=embedvar)
Upvotes: 0
Views: 94
Reputation: 71542
Your types are all mismatched:
whitelist = "562448514349662208" # type: str
user = int(message.author.id) # type: int <-- I don't think you want this!
if message.author == bot.user:
content = message.content[3:] # type: str
color = discord.Color(value=int("%06x" % random.randint(0, 0xFFFFFF), 16))
embedvar = discord.Embed(description=content, color=color)
await message.delete()
await message.channel.send(embed=embedvar)
if user == whitelist:
content = message.content[3:] # type: str
color = discord.Color(value=int("%06x" % random.randint(0, 0xFFFFFF), 16))
embedvar = discord.Embed(description=content, color=color)
await message.channel.send(embed=embedvar)
else:
content = user # type: int
color = discord.Color(value=int("%06x" % random.randint(0, 0xFFFFFF), 16))
embedvar = discord.Embed(description=content, color=color)
await message.channel.send(embed=embedvar)
Based on the fact that content
is assigned to a string slice (I think?) in two of these branches, I'm guessing you actually want user
to be a string as well, both for comparison to the whitelist and for setting content
. Just remove the int
conversion from the second line.
Upvotes: 0
Reputation: 1177
whitelist = "562448514349662208"
user = int(message.author.id)
if message.author == bot.user:
content = message.content[3:]
color = discord.Color(value=int("%06x" % random.randint(0, 0xFFFFFF), 16))
embedvar = discord.Embed(description=content, color=color)
await message.delete()
await message.channel.send(embed=embedvar)
if user == int(whitelist):
content = message.content[3:]
color = discord.Color(value=int("%06x" % random.randint(0, 0xFFFFFF), 16))
embedvar = discord.Embed(description=content, color=color)
await message.channel.send(embed=embedvar)
else:
content = user
color = discord.Color(value=int("%06x" % random.randint(0, 0xFFFFFF), 16))
embedvar = discord.Embed(description=content, color=color)
await message.channel.send(embed=embedvar)
You are comparing a string to an int...they need to be the same type to check if they are the same.
Upvotes: 2