假设我有一个像这样的异步函数:
async def foobar(argOne, argTwo, argThree):
print(argOne, argTwo, argThree)
Run Code Online (Sandbox Code Playgroud)
我想制作一个装饰器并在此函数上使用它,将上面的代码包装在 try except 语句中,如下所示:
try:
print(argOne, argTwo, argThree)
except:
print('Something went wrong.)
Run Code Online (Sandbox Code Playgroud)
有什么办法可以做到这一点吗?
情况:
我正在尝试使用 pycord 制作一个简单的不和谐机器人,但每次运行代码时都会出现以下错误:
Traceback (most recent call last):
File "main.py", line 3, in <module>
bot = discord.Bot()
AttributeError: module 'discord' has no attribute 'Bot'
Run Code Online (Sandbox Code Playgroud)
代码:
Traceback (most recent call last):
File "main.py", line 3, in <module>
bot = discord.Bot()
AttributeError: module 'discord' has no attribute 'Bot'
Run Code Online (Sandbox Code Playgroud)
我做了什么:
我已经检查过我是否安装了 pycord 以及我的令牌是否正确。
我的 Pycord 机器人中有一个斜杠命令。这是代码:
@bot.slash_command(name='greet', description='Greet someone!')
async def greet(ctx, name):
await ctx.send('Hello ' + name + '!')
Run Code Online (Sandbox Code Playgroud)
我如何使“名称”成为可选参数?我尝试设置 name=None,但它不起作用。