I don't understand why it gives this error! It's eating my head
@client.event
async def on_message(message):
# Make sure bot doesn't get stuck in an infinite loop
if message.author == client.user:
return
# Get data about the user
username = str(message.author)
user_message = str(message.content)
channel = str(message.channel)
# Debug printing
print(f"{username} dice: '{user_message}' ({channel})")
# If the user message contains a '?' in front of the text, it becomes a private message
if user_message[0] == '?':
user_message = user_message[1:] # [1:] Removes the '?'
await send_message(message, user_message, is_private=True)
else:
await send_message(message, user_message, is_private=False)
The only thing it does there is call a module called "send_message"
async def send_message(message, user_message, is_private):
try:
response = responses.handle_response(user_message)
await message.author.send(response) if is_private else await message.channel.send(response)
except Exception as e:
print(e)
def handle_response(message) -> str:
p__message = message.lower()
if p__message == 'tell me something bana':
return random.choice(bana_phrases)
400 Bad Request (error code: 50006): Cannot send an empty message
CodePudding user response:
You should use a check to make sure handle_response
function returns a string (it does not if the message is not tell me something bana):
async def send_message(message, user_message, is_private):
try:
response = responses.handle_response(user_message)
if response:
await message.author.send(response) if is_private else await message.channel.send(response)
except Exception as e:
print(e)