C
C
Chexit2021-11-09 20:23:58
Python
Chexit, 2021-11-09 20:23:58

Discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'str' object has no attribute 'id'?

Discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'str' object has no attribute 'id'?
The code:

import discord
from discord.ext import commands
 
from discord_slash import SlashCommand
from discord_slash.utils.manage_commands import create_option
 
client = commands.Bot(command_prefix = '.', intents = discord.Intents.all())
slash = SlashCommand(client, sync_commands = True)
 
@slash.slash(name = 'mko', description = 'добавить в мко', options = [{"name": "member", "description": "пользователь", "type": 6, "requied": True}], guild_ids = [907669402181316638])
@client.command(aliase = ['mko'])
 
async def mko(ctx, member: discord.Member, pass_context=True):
  await member.add_roles("907678577758203915")

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
retUrn3d, 2021-11-09
@Chexit

It is enough to add literally one line to your code.

role = discord.utils.get(member.guild.roles, id=907678577758203915)
await member.add_roles(role)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question