IBeCodin'
IBeCodin'

Reputation: 11

discord.py outputing the result of eval

recently I've started making a bot in python. part of this bot requires me to send the result of an eval into the chat. I can't seem to figure out how to do this, this is the code I have currently

sMessage = "print('hello world')"
var1 = eval(sMessage)
await message.channel.send(var1)

I'm not sure what I'm missing here.

Thanks

edit: Fix typo in example code, the error this code gives is "400 Bad Request (error code: 50006): Cannot send an empty message "

Upvotes: 1

Views: 245

Answers (2)

Eastonco
Eastonco

Reputation: 105

The issue is that you're using the " multiple times without denoting when you want to display the character vs use it to terminate your string. You want to add a \ before special characters to denote they're to be displayed rather than terminate your string

sMessage = "print(\"hello world\")"

Another solution would be to swap the double quotes to single quotes

sMessage = "print('hello world')"

Hope that makes sense

Upvotes: 1

NrdyBhu1
NrdyBhu1

Reputation: 383

See its wrong ,you missed a quote so it should be

sMessage = "print('hello world')"
var1 = eval(sMessage)
await message.channel.send(var1)

Be carefull next, (I am not scolding you)

Upvotes: 0

Related Questions