繁体   English   中英

Discord,py 命令在 cogs 中以前有效,但在使用时找不到

[英]Discord,py commands in cogs that previously worked now are not found upon using them

提示:本站提供中英文对照查看,鼠标放在中文字句上可显示英文原文。 若本文未解决您的问题,推荐您尝试使用帮您解决。

我有一段时间没有更改运行 discord.py 的 discord 机器人中的代码。 它之前工作,但半年后突然停止工作,因为代码在没有任何操作的情况下不知何故坏了。 该机器人运行,甚至能够使用在 main.py 文件中实现的命令。 但是,当尝试运行用 cogs 编写的命令时,例如 help.py,它只会给我以下错误:

    2022-09-27 14:58:00 ERROR    discord.ext.commands.bot Ignoring exception in command None
    discord.ext.commands.errors.CommandNotFound: Command "help" is not found

这是我在 main.py 中的代码

#Library of imports
#---------------------------------------------------#
#Basic DC stuff
import discord
from discord.ext import commands, tasks
from discord.utils import find
#On message
from discord import Message
#OS
from dotenv import load_dotenv
from os import getenv
import os
#Status etc.
import math
import random
from random import choice
#Date & Time
import datetime
import time
#Misc
import functools
import itertools
import asyncio
from async_timeout import timeout
#Uptime
from keepalive import keepalive
#My imports
import settings
from settings import DISCORD_TOKEN

#---------------------------------------------------#
#intents = discord.Intents.all() #stopped for the moment, doesn't work - working version implemented in line 44 "intents=discord.Intents()"
intents = discord.Intents.default()
intents.members = True
intents.message_content = True
#-------------------Loads---------------------------#
load_dotenv()
status = [
    "sheep noises", "Fujara", "Life", "Horse nagging", "Sheep bliating",
    "Sheep™", "Sheep Simulator"
]

bot = commands.Bot(command_prefix='$',
                   case_insensitive=True,
                   help_command=None,
                   intents=intents)

initial_extensions = [
    'embed',
    'ent',
    'help',
    'music',
]

if __name__ == "__main__":
    for extension in initial_extensions:
       bot.load_extension(extension)


#---------------------------------------------------#
#Ready event htps
@bot.event
async def on_ready():
    change_status.start()
    print(f'Logged in as {bot.user} (ID: {bot.user.id})')
    print(datetime.datetime.now())
    print(f'Ping: {round(bot.latency * 1000)}ms')
    print('--------------------------------------------------------')


@bot.event
async def on_guild_join(guild):
    general = find(lambda x: x.name == 'general', guild.text_channels)
    embed = discord.Embed(title=("**Hello-{}!**".format(guild.name)),
                          colour=discord.Colour.dark_purple(),
                          description="Prefix[!]")
    embed.set_footer(text="Sheep™")
    if general and general.permissions_for(guild.me).send_messages:
        await general.send(embed=embed)


#----------------------commands-----------------------------------#
#Bot stop command - add embed
@bot.command(name='botstop', aliases=['bstop', 'end'])
@commands.is_owner()
async def botstop(ctx):
    print('Commiting sudoku')
    await ctx.send('I committed sudoku')
    await bot.logout()
    return


#Clear command
@bot.command(aliases=['purge', 'delete'])
@commands.has_permissions(manage_messages=True)
async def clear(ctx, amount: int):
    if amount == None:
        await ctx.channel.purge(limit=1000000)
    else:
        await ctx.channel.purge(limit=amount)


#Ping command - embed
@bot.command(name="ping", pass_context=True)
async def ping(ctx):
    embed = discord.Embed(title="**PING**",
                          colour=discord.Colour.dark_purple(),
                          description=(f'{round(bot.latency * 1000)}ms'))
    embed.set_footer(text="Sheep™")
    embed.set_author(name=ctx.author.display_name, icon_url=ctx.author.avatar)
    await ctx.send(embed=embed)


#Task loop for chg
@tasks.loop(seconds=2)
async def change_status():
    await bot.change_presence(activity=discord.Game(choice(status)))


#-------------------------Function startup------------------------#

keepalive()
bot.run(DISCORD_TOKEN)

这是我在示例 cog 中的代码。

#Library of imports
#---------------------------------------------------#
import discord
from discord.ext import commands
from discord import Message

#---------------------------------------------------#


#----------------------COG--------------------------#
class MyCog(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    #Default help command
    @commands.command()
    async def help(self, ctx):
        embed = discord.Embed(title="Sheep™",
                              url="https://youtu.be/EuGRKqTwbVI",
                              description="** **",
                              colour=discord.Colour.dark_purple())
        embed.set_author(name=ctx.author.display_name,
                         icon_url=ctx.author.avatar_url)
        embed.set_thumbnail(
            url=
            "https://www.visitliptov.sk/wp-content/uploads/2021/05/LIPTOV-LOGO_white-2048x2048.png"
        )

        embed.add_field(
            name="**HELP**",
            value="This command shows functions of every command. Prefix{!}",
            inline=False)
        embed.add_field(name="**Admin**",
                        value="|`Load`|`Unload`|`Reload`|`Status`|`Botstop`|",
                        inline=True)
        embed.add_field(name="**Fun**",
                        value="|`Embed`|`Sheep`|`Date`|",
                        inline=True)
        embed.add_field(name="**Misc**",
                        value="|`Ping`|`Uptime`|`Clear`|`Avatar`|",
                        inline=True)
        embed.add_field(name="**Music**", value="|`WIP`|", inline=False)
        embed.set_footer(text="Sheep™")
        await ctx.send(embed=embed)


def setup(bot):
    bot.add_cog(MyCog(bot))



暂无回复试试使用:帮您解决问题。
暂无
暂无

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

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