繁体   English   中英

Discord.py 更新 Python 版本后 on_message_delete(message) 出现新错误

[英]Discord.py New error with on_message_delete(message) after updating Python version

因此,简而言之,自从更新 Python 并重定向新的 pip 后,我的代码基本上有一半无法正常工作——我读到这很常见,我不确定如何修复它,但一次只能解决一个步骤。 我想快速修复的是:

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)

现在我得到这个错误:

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

内容不超过 2000 个字符,但如您所见,我已经有了针对该确切情况的 if/else。 抱歉,如果这是一个简单的解决方案,谢谢您的帮助。

注意:我尝试添加await bot.process_commands(message)因为我有更多 on_ 情况甚至没有运行,但这没有区别。

由于这比这更大,这里有一个关于什么是有效的和什么是无效的概念,含糊地:

在职的:

  • on_ready(打印语句,活动存在更新)
  • 所有具有角色反应的现有嵌入都可以按需工作
  • on_invite 函数

不工作:

  • 所有命令
  • 调用任何嵌入
  • 任何 on_message 函数

为了能见度,我所有的进口:

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冻结:

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

更新:呃.. 所以命令和类似的东西在 DMs 中工作到机器人而不是在我的服务器中......所以这是一大块信息应该帮助我找出问题所在

问题不是 python 版本的更新。 message.content可以为空(例如仅发送一个文件)。 结果,该字段的名称是一个无效的空字符串,并且会引发所描述的错误,因为它仍然会执行 if else 代码的 if 部分。

当我更新到启用 discord.py message_intents 的最新版本时,没有任何工作的问题是一个额外的要求。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM