[英]discord.py bot "The check functions for command failed"
我正在制作一個 discord 機器人,每次我嘗試從 cog 運行命令時,如果出現此錯誤
Traceback (most recent call last):
File "C:\Users\addis\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\addis\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 855, in invoke
await self.prepare(ctx)
File "C:\Users\addis\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 778, in prepare
raise CheckFailure('The check functions for command {0.qualified_name} failed.'.format(self))
discord.ext.commands.errors.CheckFailure: The check functions for command avatar failed.
這是我的代碼
import os
from discord.ext import commands
bot = commands.Bot(
command_prefix="!", # Change to desired prefix
case_insensitive=True # Commands aren't case-sensitive
)
bot.author_id = DISCORD ID
@bot.event
async def on_ready(): # When the bot is ready
print("I'm in")
print(bot.user) # Prints the bot's username and identifier
extensions = [
'cogs.cog_example', 'cogs.cog_start' # Same name as it would be if you were importing it
]
if __name__ == '__main__': # Ensures this is the file being ran
for extension in extensions:
bot.load_extension(extension) # Loades every extension.
token = "TOKEN"
bot.run(token) # Starts the bot
這是有問題的齒輪
import discord
from discord.ext import commands
class start(commands.Cog, name='start Commands'):
'''These are the start commands'''
def __init__(self, bot):
self.bot = bot
async def cog_check(self, ctx):
'''
The default check for this cog whenever a command is used. Returns True if the command is allowed.
'''
return ctx.author.id == self.bot.author_id
@commands.command(name="avatar", aliases=['av'])
async def avatar(self, ctx):
print("bruh")
def setup(bot):
bot.add_cog(start(bot))
我想知道這是怎么回事以及我該如何解決它(我使用的是模板)
如果你添加了一個名字
class start(commands.Cog, name='start Commands'):
您必須將其添加到設置 function:
def setup(bot):
bot.add_cog(start(bot), name='start Commands')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.