[SOLVED] Exception: 400 Bad Request (error code: 50006): Cannot send an empty message while using embed in discord.py


This Content is from Stack Overflow. Question asked by star

async def who(ctx):
  embed=discord.Embed(title=r1, color=0xC964F0)
  await ctx.send(embed=embed)

async def nhie(ctx):
  embed=discord.Embed(title=r2, color=0xC964F0)
  await ctx.send(embed=embed)

async def truth(ctx):
  embed=discord.Embed(title=r3, color=0xC964F0)
  await ctx.send(embed=embed)

async def dare(ctx):
  embed=discord.Embed(title=r4, color=0xC964F0)
  await ctx.send(embed=embed)

Code was working fine in discord, the bot responded to the commands when I used it earlier but then whenever I do it now, it gives me an error, even though I have not touched the code since.

Ignoring exception in command truth:
Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 92, in wrapped
    ret = await coro(*args, **kwargs)
  File "main.py", line 1254, in truth
    await ctx.send(embed=embed)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/abc.py", line 1089, in send
    data = await state.http.send_message(
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/http.py", line 262, in request
    raise HTTPException(r, data)
discord.errors.HTTPException: 400 Bad Request (error code: 50006): Cannot send an empty message

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 977, in invoke
    await ctx.command.invoke(ctx)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 870, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 101, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: HTTPException: 400 Bad Request (error code: 50006): Cannot send an empty message

the same code working just fine earlier


Okay what I think is happening is when you write :!test The !test is triggered in the other channel which in turn triggers the embed to come through the other channel as you have the line if message.content.startswith('!test') which is not channel specific.

However the problem that is occurring is while the on_message event function gets called when the embed gets sent. The embed has no content so when you try send this out in the line await test_channel.send(message.content) The error occurs as the message.content is empty (as an embed is not content).

A cheat way of fixing this is just adding the line if message.content: above the await test_channel.send(message.content) as the embed gets sent through anyways due to !test being sent in the other channel.

Otherwise you should read this post to see how to get embed information out of a message (in brief its embed_content_in_dict = message.embeds[0].to_dict())

Hope this makes sense :).

Answered by x-1-x

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 4.0.

people found this article helpful. What about you?