import discord
from discord.ext import commands
class Text(commands.Cog):
def __init__(self, client):
self.client = client
@commands.command()
@commands.has_permissions(administrator=True)
async def text(self, ctx, *, message):
await ctx.message.delete()
await ctx.send(message)
@text.error()
async def text_error(self, error, ctx):
if isinstance(error, commands.MissingPermissions):
await ctx.send(f"{ctx.auhtor.mention} You don't Have permission to use this command")
def setup(client):
client.add_cog(Text(client))
整个错误是:
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 609, in _load_from_module_spec
raise errors.ExtensionFailed(key, e) from e
discord.ext.commands.errors.ExtensionFailed: Extension 'cogs.text' raised an error: TypeError: error() missing 1 required positional argument: 'coro'
这是因为您的代码中有一些错误:
@text.error()
应替换为@text.error
text_error
函数中交换了ctx
和error
{ctx.auhtor.mention}
中输入了一个错误最终代码:
相关问题 更多 >
编程相关推荐