当我尝试运行该命令时,我总是收到此错误消息:discord.ext.commands.errors.ExtensionFailed:扩展 'cogs.unban' 引发错误:类型错误:cogs 必须从 Cog 派生 sys:1: RuntimeWarning: coroutine 'Command.call' 从未被等待
import discord
from discord.ext import commands
class unban(commands.Cog):
def __init__(self, client):
self.client = client
# Commandok
@commands.command()
async def unban(ctx, *, member): # unindent
banned_users = await ctx.guild.bans() # unindent
member_name, member_discriminator = member.split('#') # unindent
for ban_entry in banned_users:
user = ban_entry.user
if (user.name, user.discriminator) == (member_name, member_discriminator):
await ctx.guild.unban(user)
await ctx.send(f'Unbanned {user.mention}')
return
def setup(client):
client.add_cog(unban(client))
我收到以下错误:
File "K:\Discord BOT\PythonX\Bot.py", line 74, in <module>
client.load_extension(f'cogs.{filename[:-3]}')
File "C:\Users\NexaHn\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 663, in load_extension
self._load_from_module_spec(spec, name)
File "C:\Users\NexaHn\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 623, in _load_from_module_spec
raise errors.ExtensionFailed(key, e) from e
discord.ext.commands.errors.ExtensionFailed: Extension 'cogs.unban' raised an error: TypeError: cogs must derive from Cog
sys:1: RuntimeWarning: coroutine 'Command.__call__' was never awaited
答案 0 :(得分:0)
class Administration(commands.Cog):
def __init__(self,bot):
self.bot = bot
@commands.command()
async def unban(self, ctx,*,member):
# your function
def setup(bot):
bot.add_cog(Administration(bot))
看这个 -> https://discordpy.readthedocs.io/en/latest/ext/commands/cogs.html