Discord Botu hata: 400 Bad Request (error code: 50006): Cannot send an empty message

Pythonda discord botu kodu buldum internette ve bunu kendim denemeye karar verdim ve kod bu

import discord
import responses


# Send messages
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 run_discord_bot():
    TOKEN = 'MTEyMTM4OTY5NTI1NTk3MzkyOA.GGkvdQ.0OCA0fHGVCZ4ROW0ER1u0eZm82MalZZ6qDgeLc'
    client = discord.Client()

    @client.event
    async def on_ready():
        print(f'{client.user} is now running!')

    @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} said: '{user_message}' ({channel})")
    
        # If the user message contains a '?' in front of the text, it becomes a private message
        
        
        await send_message(message, user_message, is_private=False)

    # Remember to run your bot with your personal TOKEN
    client.run(TOKEN)

buda
cevaplar

import random


def handle_response(message) -> str:
    p_message = message.lower()
    if p_message == 'merhaba':
        return 'merhaba'

    if p_message == 'roll':
        return str(random.randint(1, 6))

    if p_message == '!help':
        return "Merhaba : Merhaba"

hata şu: herhangi bir mesaj yazınca sunucuda cevap vermiyor
hata ;

400 Bad Request (error code: 50006): Cannot send an empty message

Hata üzerinden yola çıkabilirdiniz aslında. Hatada boş mesajın gönderilemeyeceği yazıyor. Bu durum ise handle_response fonksiyonunda tüm koşullara uymadığı zaman döndüğü None değerinden dolayı oluşuyor. Kodu handle_response fonksiyonu boş olmayan bir string döndürmediği zaman mesaj gönderecek şekilde ayarlayabilirsiniz:

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)