burner_acc_imdumb
burner_acc_imdumb

Reputation: 3

Discord.py sends an odd message format in randomizing commands

Apologies for the confusing title, I didn't know how to describe the problem in one sentence. Discord.py has been sending messages with punctuation or parenthesis that weren't there in the code, this is happening for several commands and I've tried rearranging variables to no success. Does anyone know how to fix this This is my code:

        valid_level = random.randint(0,100)
        valid_message =  " you are ",valid_level,"% valid "
        await client.send_message(message.channel,valid_message)

Instead of sending " you are (variable generated %) valid", the bot sends " (' you are ', 48, % valid ') " as the message.

Upvotes: 0

Views: 44

Answers (1)

Jab
Jab

Reputation: 27495

This line

valid_message =  " you are ",valid_level,"% valid "

creates a tuple: (' you are ', 48, % valid ')

You need to str.format

valid_message =  " you are {}% valid ".format(valid_level)
#or
valid_message =  f" you are {valid_level}% valid "

Upvotes: 2

Related Questions