Discord.py未加载命令



大家好,我正在使用python 3.8在discord.py中制作一个discordbot。我做了一些cog,每当我键入load-cog命令或unload-cog时,它都不会显示任何问题bot,它显示的命令找不到。我的齿轮只有一个在工作,另一个不工作,请帮帮我。

我的Bot.py(主文件(

import discord
import os
from discord.ext import commands
from discord.ext.commands import CommandNotFound

client = commands.Bot(command_prefix = '#')

@client.command
async def load(ctx, extension):
client.load_extension(f'cogs.{extension}')
@client.command
async def unload(ctx, extension):
client.unload_extension(f'cogs.{extension}')
for filename in os.listdir('./cogs'):
if filename.endswith('.py'):
client.load_extension(f'cogs.{filename[:-3]}')

client.run('BOT TOKEN')

我的第一个cog文件main.py

import discord
from discord.ext import commands

class main(commands.Cog):
def __init__(self, client):
self.client = client
#Events
@commands.Cog.listener()
async def on_ready(self):
print('Bot is online.')
# Commands
@commands.command(name='ping',help='Sends the latency of the Bot')
async def ping(self, ctx):
await ctx.send(f'**Pong!** Latency: {round(self.client.latency * 1000)}ms')

def setup(client):
client.add_cog(main(client))

我的2齿轮文件调节.py

import discord
from discord.ext import commands

class moderation(commands.Cog):
def __init__(self, client):
self.client = client
@commands.command(name='clear', help='deletes no. of messages you give it')
async def clear(ctx, amount = 1000):
await ctx.channel.purge(limit=amount)
def setup(client):
client.add_cog(moderation(client))

您的缩进是错误的-您在__init__中而不是在类本身中声明了命令。

def __init__(self, client):
self.client = client
@commands.command(name='clear', help='deletes no. of messages you give it')
async def clear(ctx, amount = 1000):
await ctx.channel.purge(limit=amount)

最新更新