用hikari和Lightbulb扮演角色

发布于 2025-02-03 11:15:38 字数 2665 浏览 4 评论 0原文

我想,当命令运行时,会给那些担任特定角色的人,并另一个命令删除角色。我该怎么做?

@bot.command
@lightbulb.command('getpings', 'Will be Pinged (/help For More Info)')
@lightbulb.implements(lightbulb.SlashCommand)
async def give_pings(ctx):
         await bot.rest.add_role_to_member(user=ctx.author, guild=ctx.guild_id, role=roleid)

错误:

E 2022-06-09 21:23:29,648 hikari.event_manager: an exception occurred handling an event (InteractionCreateEvent)
Traceback (most recent call last):
  File "C:\Users\avih2\AppData\Local\Programs\Python\Python310\lib\site-packages\lightbulb\app.py", line 1154, in invoke_application_command
    await context.invoke()
  File "C:\Users\avih2\AppData\Local\Programs\Python\Python310\lib\site-packages\lightbulb\context\base.py", line 292, in invoke
    await self.command.invoke(self)
  File "C:\Users\avih2\AppData\Local\Programs\Python\Python310\lib\site-packages\lightbulb\commands\base.py", line 544, in invoke
    await self(context, **kwargs)
  File "C:\Users\avih2\AppData\Local\Programs\Python\Python310\lib\site-packages\lightbulb\commands\base.py", line 459, in __call__
    return await self.callback(context, **kwargs)
  File "c:\Users\avih2\Desktop\PyProjects\API Test\bot.py", line 35, in give_pings
    await bot.rest.add_role_to_member(user=ctx.author, guild=ctx.guild_id, role=roleid)
  File "C:\Users\avih2\AppData\Local\Programs\Python\Python310\lib\site-packages\hikari\impl\rest.py", line 2705, in add_role_to_member
    await self._request(route, reason=reason)
  File "C:\Users\avih2\AppData\Local\Programs\Python\Python310\lib\site-packages\hikari\impl\rest.py", line 820, in _request
    await self._handle_error_response(response)
  File "C:\Users\avih2\AppData\Local\Programs\Python\Python310\lib\site-packages\hikari\impl\rest.py", line 842, in _handle_error_response
    raise await net.generate_error_response(response)
hikari.errors.ForbiddenError: Forbidden 403: (50013) 'Missing Permissions' for https://discord.com/api/v8/guilds/980618833838624821/members/439959575647748096/roles/980948889567911958

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\avih2\AppData\Local\Programs\Python\Python310\lib\site-packages\lightbulb\app.py", line 1195, in handle_interaction_create_for_application_commands
    await self.invoke_application_command(context)
  File "C:\Users\avih2\AppData\Local\Programs\Python\Python310\lib\site-packages\lightbulb\app.py", line 1172, in invoke_application_command
    raise new_exc
lightbulb.errors.CommandInvocationError: An error occurred during command 'getpings' invocation

I want to, when a command is ran give the person who ran it a certain role and another command to remove the role. How would I do this?

@bot.command
@lightbulb.command('getpings', 'Will be Pinged (/help For More Info)')
@lightbulb.implements(lightbulb.SlashCommand)
async def give_pings(ctx):
         await bot.rest.add_role_to_member(user=ctx.author, guild=ctx.guild_id, role=roleid)

Error:

E 2022-06-09 21:23:29,648 hikari.event_manager: an exception occurred handling an event (InteractionCreateEvent)
Traceback (most recent call last):
  File "C:\Users\avih2\AppData\Local\Programs\Python\Python310\lib\site-packages\lightbulb\app.py", line 1154, in invoke_application_command
    await context.invoke()
  File "C:\Users\avih2\AppData\Local\Programs\Python\Python310\lib\site-packages\lightbulb\context\base.py", line 292, in invoke
    await self.command.invoke(self)
  File "C:\Users\avih2\AppData\Local\Programs\Python\Python310\lib\site-packages\lightbulb\commands\base.py", line 544, in invoke
    await self(context, **kwargs)
  File "C:\Users\avih2\AppData\Local\Programs\Python\Python310\lib\site-packages\lightbulb\commands\base.py", line 459, in __call__
    return await self.callback(context, **kwargs)
  File "c:\Users\avih2\Desktop\PyProjects\API Test\bot.py", line 35, in give_pings
    await bot.rest.add_role_to_member(user=ctx.author, guild=ctx.guild_id, role=roleid)
  File "C:\Users\avih2\AppData\Local\Programs\Python\Python310\lib\site-packages\hikari\impl\rest.py", line 2705, in add_role_to_member
    await self._request(route, reason=reason)
  File "C:\Users\avih2\AppData\Local\Programs\Python\Python310\lib\site-packages\hikari\impl\rest.py", line 820, in _request
    await self._handle_error_response(response)
  File "C:\Users\avih2\AppData\Local\Programs\Python\Python310\lib\site-packages\hikari\impl\rest.py", line 842, in _handle_error_response
    raise await net.generate_error_response(response)
hikari.errors.ForbiddenError: Forbidden 403: (50013) 'Missing Permissions' for https://discord.com/api/v8/guilds/980618833838624821/members/439959575647748096/roles/980948889567911958

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\avih2\AppData\Local\Programs\Python\Python310\lib\site-packages\lightbulb\app.py", line 1195, in handle_interaction_create_for_application_commands
    await self.invoke_application_command(context)
  File "C:\Users\avih2\AppData\Local\Programs\Python\Python310\lib\site-packages\lightbulb\app.py", line 1172, in invoke_application_command
    raise new_exc
lightbulb.errors.CommandInvocationError: An error occurred during command 'getpings' invocation

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

々眼睛长脚气 2025-02-10 11:15:38

首先,您将必须获得要添加/删除角色的角色ID。

假设您要添加的角色的变量称为ralemid。

您可以使用lightbulb.botapp.rest.add_role_to_member向成员添加角色。
假设您有一个称为bot的变量,则在该变量下实例化lightbulb.botapp,

await bot.rest.add_role_to_member(user=ctx.author, guild=ctx.guild_id, role=roleid)

First of all, you're going to have to get the role ID of the role you want to add/remove.

Let's assume the variable for the role you want to add is called roleid.

You can use lightbulb.BotApp.rest.add_role_to_member to add a role to a member.
assuming you have a variable called bot under which you instantiate lightbulb.BotApp,

await bot.rest.add_role_to_member(user=ctx.author, guild=ctx.guild_id, role=roleid)
鲜肉鲜肉永远不皱 2025-02-10 11:15:38

您的代码很好,但是要添加到用户的角色需要在机器人角色下。 (idk为什么,但这对我有用)

Your code is good, but the role you want to add to user needs to be under the bot role. (idk why but that worked for me)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文