#๐Ÿ”’ can't convert non-string with explicit base

47 messages ยท Page 1 of 1 (latest)

velvet basin
#

can't convert non-string with explicit base

fading archBOT
#

@velvet basin

Python help channel opened

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.

velvet basin
#

hi again

blazing ledge
#

You appear to be passing something other than a string to int, and are specifying a base as the second argument to int.

#

Hello.

velvet basin
#

lemme send

#

!code

fading archBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

velvet basin
#
@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

blazing ledge
#

That error means that y isn't a string.

#

Print it out to see what it actually is.

velvet basin
#

it said to me that the (number, 16) cannot be converted nonstring

velvet basin
blazing ledge
velvet basin
#

so what do i have to do

blazing ledge
#

!e

int(5, 16)
fading archBOT
#

@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
velvet basin
#

omg

blazing ledge
#

If it's a number and you want to just get a hex repr, you can use the hex function.

velvet basin
#

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

blazing ledge
#

Oh, actually, it's not necessarily y that's the problem. You're doing this effectively:

#

!e

int(808080, 16)
fading archBOT
#

@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
blazing ledge
#

Since number is a number. But yes, if you just want the hex repr, use hex:

#

!e

print(hex(808080))
fading archBOT
#

@blazing ledge :white_check_mark: Your 3.12 eval job has completed with return code 0.

0xc5490
velvet basin
#

so i just

#

do what

#

like

#

do i

#

colorhex = print(hex(808080))

#

?

blazing ledge
#

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 #.

velvet basin
#

so what do i do?

#

it doesnt want the #

#

it just wants the pure number

#

without any #

blazing ledge
#

Maube just pass number directly?

fading archBOT
#
Python help channel closed

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.