Home > other >  Discord.py New error with on_message_delete(message) after updating Python version
Discord.py New error with on_message_delete(message) after updating Python version

Time:03-21

So, in short, basically half of my code isn't working since updating Python and redirecting a new pip - I read this is common and I'm not sure how to fix it but 1 step at a time. The quick thing I want to fix is this:

async def on_message_delete(message):
    if message.author.bot == False:
        if message.channel.id != <censored>:
            em = discord.Embed(title=str(message.author),description="deleted a message.", color=red)
            if len(str(message.content)) < 1000:
                em.add_field(name = str(message.content), value="(message contents)")
            else:
                em.add_field(name = "[content greater than 1000 characters]", value="(message contents)")
            em.add_field(name = str(message.channel), value="(location)")
            events_channel = bot.get_channel(<censored>)
            await events_channel.send(embed=em)

Now I get this error:

Traceback (most recent call last):
  File "C:\Users\alipe\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\client.py", line 373, in _run_event
    await coro(*args, **kwargs)
  File "C:\Users\alipe\Desktop\Discord Server\Luna.py", line 677, in on_message_delete
    await events_channel.send(embed=em)
  File "C:\Users\alipe\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\abc.py", line 1419, in send
    data = await state.http.send_message(channel.id, params=params)
  File "C:\Users\alipe\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\http.py", line 501, in request
    raise HTTPException(response, data)
discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In embeds.0.fields.0.name: This field is required

The content isn't over 2000 characters but as you can see, I already have an if/else for that exact situation. Sorry if this is a simple solution, thank you for any help.

Note: I have tried adding await bot.process_commands(message) since I have more on_ situations that aren't even running but this made no difference.

Since this is bigger than this, here is an idea of what is and isn't working, vaguely:

Working:

  • on_ready (a print statement, an activity presence update)
  • all existing embeds with role reactions work as desired
  • on_invite functions

Not Working:

  • all commands
  • calling any embeds
  • any on_message functions

For visibility, all my imports:

from discord import Color
from discord.ext import commands
from discord.ext.commands import has_permissions, CheckFailure
import dislash
from dislash import InteractionClient, SelectMenu, SelectOption, ActionRow, Button, ButtonStyle
import os, random, json, time, asyncio, sys, traceback, calendar

pip freeze:

aiohttp==3.7.4.post0
async-timeout==3.0.1
attrs==21.4.0
chardet==4.0.0
discord==1.7.3
discord.py @ git https://github.com/Rapptz/discord.py@515d17405a9eda9f457746193b9b8722ab17b2e6
dislash.py==1.4.9
disnake==2.4.0
idna==3.3
multidict==6.0.2
typing_extensions==4.1.1
yarl==1.7.2

update: uh.. so the commands and such work in DMs to the bot but not in my server...so that's a big chunk of info that should help me figure out what's wrong

CodePudding user response:

The problem isn't the update of the python version. message.content can be empty (only a file send for example). In a consequence the name of the field is an empty string which is invalid and will raise the described error, because it still will execute the if part of the if else code.

CodePudding user response:

The issue with nothing working is an extra requirement needed when I updated to the latest version of discord.py message_intents enabled.

  • Related