[英]Cogs not working in discord.py load extension
import discord
from discord.ext import commands
class CommandEvents(commands.cog):
def __init__(self, bot):
self.bot = bot
@commands.Cog.listener()
async def on_command_error(self, ctx, error):
if isinstance(error, commands.CommandNotFound):
await ctx.send("**Invalid command. Try using** `help` **to figure out commands!**")
if isinstance(error, commands.MissingRequiredArgument):
await ctx.send('**Please pass in all requirements.**')
if isinstance(error, commands.MissingPermissions):
await ctx.send("**You dont have all the requirements or permissions for using this command :angry:**")
@commands.command(name="ping")
async def ping(self, ctx: commands.Context):
await ctx.send(f"Pong! {round(self.bot.latency * 1000)}ms")
def setup(bot):
bot.add_cog(CommandEvents(bot))
那是我的齒輪。 當我嘗試設置 Bot 時,會發生這種情況。 所以 idk 我搜索了很多如何使用 cogs 但 idk。 我是齒輪的新手,這是我第一次使用它們。
我的主程序
import discord
import os
from discord.ext import commands
token = ""
bot = commands.Bot(command_prefix = '-')
bot.load_extension("CommandEvents")
bot.run(token)
我究竟做錯了什么?
cog 文件的第 4 行:您輸入了commands.cog
。 由於 Python 區分大小寫,因此您必須使用大寫的 C 鍵入commands.Cog
。 還:
您必須輸入齒輪的完整路徑。 您剛剛輸入了“CommandEvents”,但它應該是“cogs.CommandEvents”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.