maty2go
@maty2go
Начинающий програмист Discord ботов.

Ошибка в дискорд боте AttributeError: 'str' object has no attribute 'author'?

@commands.command(aliases=["k"])
    @commands.has_permissions(kick_members=True)
    async def kick(self, guild, ctx, user: nextcord.Member = None, *, reason=None):
        if user == None:
            if ctx.author.id == 403957489525063691:
                embed=nextcord.Embed(title= " " , description="Please enter a user!", color=nextcord.Colour.random())
                await guild.send (embed=embed)
                return
            else:
                embed=nextcord.Embed(title= " " , description="А ты не много хочешь ? huh ?", color=nextcord.Colour.random())
                await guild.send (embed=embed)
        elif ctx.author.id == 403957489525063691:
            await nextcord.Member.kick(self, reason=reason)
            await guild.send(f'Kicked {nextcord.Member.name} for reason {reason}')
        else:
            embed=nextcord.Embed(title= " " , description="А ты не много хочешь ? huh ?", color=nextcord.Colour.random())
            await guild.send (embed=embed)


ошибка которую выдет :

nextcord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'str' object has no attribute 'author'

консоль :

Ignoring exception in command kick:
Traceback (most recent call last):
File "C:\Users\maty2go\AppData\Local\Programs\Python\Python310\lib\site-packages\nextcord\ext\commands\core.py", line 168, in wrapped
ret = await coro(*args, **kwargs)
File "c:\Users\maty2go\Desktop\Discord bot\cogs\gay.py", line 36, in kick
if ctx.author.id == 403957489525063691:
AttributeError: 'str' object has no attribute 'author'

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

Traceback (most recent call last):
File "C:\Users\maty2go\AppData\Local\Programs\Python\Python310\lib\site-packages\nextcord\ext\commands\bot.py", line 1048, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\maty2go\AppData\Local\Programs\Python\Python310\lib\site-packages\nextcord\ext\commands\core.py", line 933, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\maty2go\AppData\Local\Programs\Python\Python310\lib\site-packages\nextcord\ext\commands\core.py", line 177, in wrapped
raise CommandInvokeError(exc) from exc
nextcord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'str' object has no attribute 'author'
  • Вопрос задан
  • 287 просмотров
Решения вопроса 1
Vindicar
@Vindicar
RTFM!
Контекст (ctx) должен быть первым параметром (ну, не считая self, конечно).
Сейчас у тебя объект контекста попадает в guild, а в ctx попадает первый аргумент команды. А так как ты не указал тип аргумента, этот аргумент так и останется строкой (str).
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
22 мая 2024, в 02:15
10000 руб./за проект
21 мая 2024, в 23:47
30000 руб./за проект