获取Hikari Lightbulb中的SlashSubCommand的作者

huangapple go评论76阅读模式
英文:

How do I get the author of a SlashSubCommand in hikari lightbulb?

问题

I'm in the process of adding a point system to a game within a discord bot. The code for the game is part of an extension file for the main AI chat bot using hikari and lightbulb as the event handlers. In order to add points to each player based on the command, it needs to be able to identify who ran the command before appending the username as a dictionary key, if it doesn't already exist, as well as assigning the point value to that key's value i.e. points[username] += 1, but I can't find any API answers or anyone else who's had this problem. I'm extremely green when it comes to hikari and lightbulb, so I'm at a total loss with how to do this.

Originally I attempted to call ctx.author, which returned an error that ctx has no method for author. My second attempt was to add an event argument to the function i.e. async def function_name(ctx, event), which returned an error that SlashSubCommand has no argument for event, which would have solved the issue by being able to just use event.author.strip('#')[0] for the username.

英文:

I'm in the process of adding a point system to a game within a discord bot. The code for the game is part of an extension file for the main AI chat bot using hikari and lightbulb as the event handlers. In order to add points to each player based on the command, it needs to be able to identify who ran the command before appending the username as a dictionary key, if it doesn't already exist, as well as assigning the point value to that key's value i.e. points[username] += 1, but I can't find any API answers or anyone else who's had this problem. I'm extremely green when it comes to hikari and lightbulb, so I'm at a total loss with how to do this.

Originally I attempted to call ctx.author, which returned an error that ctx has no method for author. My second attempt was to add and event argument to the function i.e. async def function_name(ctx, event), which return an error that SlashSubCommand has no argument for event, which would have solved the issue by being able to just use event.author.strip('#')[0] for the username.

答案1

得分: 0

我似乎在以前尝试的时候对ctx.author犯了一个错误,也许是一个我看不见的拼写错误。
对于其他遇到这个问题的人,解决方法是使用ctx.author.username,因为仅使用ctx.author会返回命令的所有用户信息的元组,如用户的数字ID。
一个使用示例是在命令函数内部使用command_author = ctx.author.username

英文:

I appear to have been incorrect in my previous attempt to ctx.author, maybe a typo that I couldn't see.
The solution for anyone else encountering this issue was solved by using ctx.author.username, as using just ctx.author returns a tuple of all the user information for the command, such as the numerical ID of the user.
An example of the use would be command_author = ctx.author.username within the command function.

huangapple
  • 本文由 发表于 2023年4月11日 12:54:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/75982509.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定