#๐ can't convert non-string with explicit base
47 messages ยท Page 1 of 1 (latest)
@velvet basin
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
hi again
You appear to be passing something other than a string to int, and are specifying a base as the second argument to int.
Hello.
@bot.command()
async def createrole(ctx, x, y, z, w, q):
number = 808080
position = q
pingable = False
if y == "0":
colorhex = int(number, 16)
colorhex1 = "8e9297"
else:
colorhex = int(y, 16)
colorhex1 = y
if x == "0":
name1 = "New role"
else:
name1 = x
if z == "True":
pingable = True
elif z == "False":
pingable = False
elif z == "0":
pingable = False
else:
await ctx.send("Fill 'Pingable' with either 'True', 'False' or '0' (for default), make sure the first letter is capitalised!")
if w == "True":
hoist = True
elif w == "False":
hoist = False
elif w == "0":
hoist = False
else:
await ctx.send("Fill 'hoisted' with either 'True', 'False' or '0' (for default), make sure the first letter is capitalised!")
new_role = await ctx.guild.create_role(name=name1,color=discord.Colour(colorhex), mentionable=pingable)
await new_role.edit(position=position, hoisted = hoist)
await ctx.send(f"Role {name1} has been successfully created, with the properties of: name={name1}, hex_color={colorhex1}({colorhex}), pingable={pingable} and position={q})", delete_after=20)
help me fix this garbage
its supposed to be a create role command with as many options as humanly possible
it said to me that the (number, 16) cannot be converted nonstring
what do you mean by that
No, it's saying that because you supplied a base (16), y must be a string, and isn't.
so what do i have to do
!e
int(5, 16)
@blazing ledge :x: Your 3.12 eval job has completed with return code 1.
001 | Traceback (most recent call last):
002 | File "/home/main.py", line 1, in <module>
003 | int(5, 16)
004 | TypeError: int() can't convert non-string with explicit base
omg
If it's a number and you want to just get a hex repr, you can use the hex function.
ok
so
i was told that i take the hex number the user gives me and convert it with 16
or smt
thats all i know
Oh, actually, it's not necessarily y that's the problem. You're doing this effectively:
!e
int(808080, 16)
@blazing ledge :x: Your 3.12 eval job has completed with return code 1.
001 | Traceback (most recent call last):
002 | File "/home/main.py", line 1, in <module>
003 | int(808080, 16)
004 | TypeError: int() can't convert non-string with explicit base
Since number is a number. But yes, if you just want the hex repr, use hex:
!e
print(hex(808080))
@blazing ledge :white_check_mark: Your 3.12 eval job has completed with return code 0.
0xc5490
No, you wouldn't use print. print doesn't return anything.
Also, you'll need to check what format discord.Color expects. You may need to replace that leading 0x with a #.
so what do i do?
it doesnt want the #
it just wants the pure number
without any #
Maube just pass number directly?
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.