【发布时间】:2021-09-15 12:41:00
【问题描述】:
我尝试在我的 cogs 文件上实现嵌入消息。当我尝试使用该命令时,我的控制台上会弹出此错误。
An exception has occurred while executing command `cal`:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord_slash/client.py", line 1352, in invoke_command
await func.invoke(ctx, **args)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord_slash/model.py", line 209, in invoke
return await self.func(self.cog, *args, **kwargs)
File "/home/runner/calculator/cogs/update.py", line 16, in cal
self.username = ctx.message.author.display_name
AttributeError: 'NoneType' object has no attribute 'author'
错误指出作者没有返回(根据我的理解)。这是我的代码 sn-p :
@ cog_ext.cog_slash(description = "Calculate your math's query.")
async def cal(self,ctx,query : str) :
self.operation = ("").join(query)
self.evaluate = eval(self.operation)
self.username = ctx.message.author.display_name
self.embed = discord.Embed(title = "/Cal", description = "Calculate your math queries.", colour = discord.Color.blurple())
self.embed.set_footer(text = f"{self.username}'s query evaluated.")
self.embed.set_author(name = f"{self.username}'s' query.", icon_url = ctx.message.author.avatar_url)
self.embed.add_field(value = f"{self.operation}", inline = False)
self.embed.add_field(value = "After evaluated, the result is :", inline = True)
self.embed.add_field(value = f"{self.evaluate}", inline = True)
await ctx.send(embed = self.embed)
根据我的直觉,我认为在 cogs 文件中,作者使用不同的关键字表示。也许我的代码有问题。提前致谢。
【问题讨论】:
-
斜杠命令使用什么库?
-
discord_slash 或 discord-py-slash-command
-
嗯,错误说
message是None,而不是.author,所以你的直觉是错误的。我对这个库一无所知,所以我无法指出实际问题来自哪里。
标签: python discord.py