You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

discord.py机器人开发报错:No module named 'discord.enums'求解决

解决discord.py机器人报错:No module named 'discord.enums'

关于enums的说明

enums(枚举)是Python中用于定义固定常量集合的类型,discord.py内部用它统一管理如消息类型、权限、文本输入样式这类有固定选项的内容,属于discord.py的核心内部模块。

报错原因及修复步骤

这个错误几乎都是因为discord相关包安装错误或损坏导致:

  • 误装了第三方的discord包(而非官方的discord.py),该包不包含discord.enums模块;
  • discord.py安装不完整、版本损坏。

修复操作:

  1. 卸载错误的包:
pip uninstall discord
  1. 重新安装官方discord.py:
pip install discord.py

若需指定稳定版本(如当前最新稳定版v2.3.2),可执行:

pip install discord.py==2.3.2

你的代码中还有几处需要修正的问题

  1. reportModal类的缩进错误及模态框项缺失:
    原代码中__init__方法内的代码缩进错误,且未将输入项添加到模态框中,修正后:
class reportModal(discord.ui.Modal):
    def __init__(self):
        super().__init__("Report a user breaking the rules") 
        
        self.report_title = discord.ui.TextInput(
            style=discord.TextInputStyle.short,
            label="User",
            required=True,
            placeholder="Name of the user you are reporting"
        )
        self.message = discord.ui.TextInput(
            style=discord.TextInputStyle.paragraph,
            label="Reason",  # 原代码重复设置label为User,此处修正为Reason更合理
            required=True,
            max_length=500,
            placeholder="Why are you reporting them"
        )
        # 必须添加这两行,将输入项加入模态框
        self.add_item(self.report_title)
        self.add_item(self.message)
  1. 命令定义及模态框调用错误:
    原@tree.command使用了错误的参数title(应为name),且调用send_modal时使用了未定义的feedback_modal,修正后:
@tree.command(name="report", description="Report a user for breaking the rules")
async def report_cmd(interaction: discord.Interaction):
    report_modal = reportModal()
    await interaction.response.send_modal(report_modal)

内容的提问来源于stack exchange,提问作者zAukz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 04:15:33