首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >nextcord.ext.commands.errors.ChannelNotFound:未找到频道"None“。(nextcord.py)

nextcord.ext.commands.errors.ChannelNotFound:未找到频道"None“。(nextcord.py)
EN

Stack Overflow用户
提问于 2021-09-11 19:16:08
回答 1查看 282关注 0票数 0

我正在用nextcord.py做一个工单系统,这是一个discord.py维护的分支。我的setup命令要求您指定一个类别ID,将在其中创建新的票证通道。下面是命令:

代码语言:javascript
复制
    @commands.command()
    async def setup(self, client, context, message : nextcord.Message=None, category : nextcord.CategoryChannel=None):
        if message is None or category is None:
            await context.channel.send("Ticket system configuration failure.")
            return

        client.ticket_configs[context.guild.id] = [message.id, message.channel.id, category.id]        

        async with aiofiles.open("ticket_configs.txt", mode="r") as file:
            data = await file.readlines()

        async with aiofiles.open("ticket_configs.txt", mode="w") as file:
            await file.write(f"{context.guild.id} {message.id} {message.channel.id} {category.id}\n")

            for line in data:
                if int(line.split(" ")[0]) != context.guild.id:
                    await file.write(line)
                    
        await message.add_reaction(u"\U0001F3AB")
        await context.channel.send("Ticket system successfully configured!")

当我在不一致的情况下运行此命令时,它会在终端中引发以下错误:

代码语言:javascript
复制
nextcord.ext.commands.errors.ChannelNotFound: Channel "None" not found.

当我从category : nextcord.CategoryChannel中删除=None时,也会引发此错误。

所有的帮助都将不胜感激!谢谢。

EN

回答 1

Stack Overflow用户

发布于 2021-09-11 20:44:17

好的,这里有一些潜在的问题:

  • 哑巴问题,但是如果您使用的是nextcord.Client,则不能使用nextcord.ext.commands,因此请使用nextcord.ext.commands.Bot而不是
  • 您正在执行的async def setup(self, client, context, ...,但是如果您使用的是齿轮,您可以使用< client >D9(如果您在__init__中定义了它)访问Nextcord,并且在实际的命令函数中,您只需确保您不能仅仅因为Nextcord在加载齿轮时运行setup就调用函数setup,因此可以这样做:

代码语言:javascript
复制
@commands.command(name='setup')
async def setupCommand(...):
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69146043

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档