【发布时间】:2021-03-16 13:32:47
【问题描述】:
大家好,我正在使用 python 3.8 在 discord.py 中制作一个不和谐机器人。我做了一些 cogs 并且每当我键入 load cog 命令或 unload cog 命令时它都没有显示任何问题机器人它的显示命令未找到。我的齿轮只有一个在工作,另一个不工作,请帮助我。
我的 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 cog 文件 moderation.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))
【问题讨论】:
标签: python-3.x discord discord.py-rewrite