simply i am making a discord bot and i got this problem :400 Bad Request (error code: 50006): Cannot send an empty message . and here is my code:
import os
import discord
import responses
async def send_message(message, user_message, is_private):
try:
response = responses.get_response(user_message)
embed=discord.Embed(
title='Bad words.',
description='Do not say bad words again,please.',
colour=discord.Colour.blue()
)
if response == 'Do not say bad words again,please':
await message.author.send(embed=embed)
else:
if is_private:
await message.author.send(response)
else :
await message.channel.send(response)
except Exception as e:
print(e)
def run_discord_bot():
TOKEN = os.environ['TOKEN']
intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)
@client.event
async def on_ready():
print(f'{client.user} is now running!')
@client.event
async def on_message(message):
if message.author == client.user:
return
username = str(message.author)
user_message = str(message.content)
channel = str(message.channel)
print(f'{username} said: "{user_message}" ({channel})')
if user_message[0] == '/':
user_message = user_message[1:]
await send_message(message, user_message, is_private=True)
else:
await send_message(message, user_message, is_private=False)
client.run(TOKEN)
code in my responses file:
import random
badWords=("badword","very bad")
def get_response(message: str) -> str:
p_message = message.lower()
if p_message == 'hi':
return 'hi'
if message == 'roll':
return str(random.randint(1, 6))
if p_message == '!help':
return '`this is a help message.`'
if p_message.find in badWords:
return 'Do not say bad words again,please'
my problem is in the bad word system because i want it to direct message an embed to anyone who say bad words but it gives this error and i will be implementing the message deletion algorithm later