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

Discord Bot开发报错:module 'discord'无StoreChannel属性

Discord机器人开发问题:AttributeError: module 'discord' has no attribute 'StoreChannel'

错误原因

你使用的discord-ui库代码中引用了discord.StoreChannel,但当前版本的discord.py已经移除或重命名了这个类——StoreChannel是旧版discord.py(v1.7及之前)的频道类型,v2.0之后已被合并或替换,导致第三方库找不到该属性。

解决建议

1. 降级discord.py到兼容版本

查找discord-ui支持的discord.py版本,比如v1.7.3,执行以下命令:

pip install discord.py==1.7.3

2. 改用discord.py原生斜杠命令(推荐)

discord.py v2.0及以上已原生支持斜杠命令,无需依赖discord-ui。重写代码示例:

import discord
from discord import app_commands
from discord.ext import commands

# 初始化Bot,需开启必要的intents
client = commands.Bot(command_prefix=" ", intents=discord.Intents.default())

@client.event
async def on_ready():
    # 同步斜杠命令到Discord服务器
    await client.tree.sync()
    print(f"已登录:{client.user}")

# 定义斜杠命令
@client.tree.command(name="hello_world", description="测试斜杠命令")
@app_commands.describe(cool="这个库是否好用(可选)")
async def hello_world(interaction: discord.Interaction, cool: bool = True):
    await interaction.response.send_message(f"你说这个库{'' if cool else '不'}好用")

# 替换为你的机器人Token
client.run("YOUR_BOT_TOKEN")

注意:确保discord.py版本≥2.0,且在Discord开发者后台开启了对应intents。

3. 修改discord-ui源码(不推荐)

找到报错的discord_ui/enums.py文件,将discord.StoreChannel替换为当前discord.py中对应的类型(比如discord.TextChannel),但这种做法可能引发其他兼容性问题,仅在必要时尝试。

内容的提问来源于stack exchange,提问作者Karl Jan Calingasan

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.20 22:06:32