我在执行以下代码时遇到错误:
import discord
from discord.ext import commands
intents = discord.Intents.default()
intents.members = True
intents.message_content = True
peoples = [
{'Name': 'Artem', 'id': 'steamid:1234'},
{'Name': 'Sergey', 'id': 'steamid:1434'},
{'Name': 'Bogdan', 'id': 'steamid:1534'}
]
bot = commands.Bot(command_prefix='/', intents=intents)
@bot.event
async def on_ready():
print(f'We have logged in as {bot.user.name}')
@bot.command()
async def accept(ctx, value: str):
id_v = None
print(value)
print(f"Command 'accept' invoked by {ctx.author.name} ({ctx.author.id}) with argument {value}")
for i in peoples:
print(i['id'])
if i['id'] == value:
id_v = i
print(id_v['id'])
break
if id_v is not None:
new_nickname = str(id_v['Name'])
print(new_nickname)
await ctx.author.edit(nick=new_nickname)
await ctx.send(f"{new_nickname} принято ✅")
print(f"Nickname updated for {ctx.author.name}")
else:
await ctx.send(f"Значение {value} не найдено в списке.")
# Replace 'YOUR_BOT_TOKEN' with your actual bot token
token = ''
# Run the bot
bot.run(token)
我在第 244 行收到此错误:
in wrapped raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: Forbidden: 403 Forbidden (error code: 50013): Missing Permissions
也许这是昵称更改的一行,但机器人启用了管理员功能,所以我什至不知道错误是什么。
即使启用了管理员权限,如果机器人的角色“低于”您要修改的成员的角色,机器人仍然可能没有足够的权限来更改某人的昵称。如果您要使用它,没有其他方法,只能将“Bot”角色拖到角色层次结构中的最高位置,高于包括“Owner”在内的所有其他角色。
以下是角色层次结构示例。
| Roles
| Bot (higher than Owner, Head Admin, etc so I can change the nicknames of all of them, etc let them enjoy my service)
| Owner
| Head Admin
| Moderator
| Verified
| @everyone
请记住,如果您没有正确配置机器人或泄漏令牌,将机器人置于高于所有角色的位置可能最终会导致严重的安全问题。
我决定了一切,由于我要求将昵称从机器人更改为我自己(即主管理员),所以出现了错误
如何为用户创建名称库
thread = await ctx.channel.create_thread(
name="принято ✅",
type=ChannelType.public_thread
)
await thread.send(f"Вам выдана <@&1189799283055132723>")