【发布时间】:2021-08-05 23:43:00
【问题描述】:
我有一个齿轮test
我有一个函数正在检查命令是否有错误。
在这个例子中,目前,如果用户在 Discord 中调用命令时没有提供参数,则会将错误打印到控制台。
我想用所述错误消息回复调用命令的原始消息 (!test)。
通常我会使用commands.Context 来执行此操作,但是由于它不是我的实现中的参数,那么最好的方法是什么?
import discord
from discord.ext import commands
class Test(commands.Cog):
def __init__(self, client):
self.client = client
@commands.command()
async def test(self, ctx, arg1):
await ctx.reply(arg1)
@test.error
async def test_error(self, error):
if isinstance(error, commands.errors.MissingRequiredArgument):
# Here I want to reply
print(error)
def setup(client):
client.add_cog(Test(client))
提前感谢您的帮助
【问题讨论】:
标签: python error-handling discord discord.py