@user1324

Перешёл с pycharm в Visual studio Code! Пишет ошибку в команде mute! что делать?

Вот код
@client.command()
async def mute(ctx, member: discord.Member, duration: str, reason):
    role = member.guild.get_role(role_id=1101411874848907299)
    role1 = member.guild.get_role(role_id=1101418348807475220)
    channel = client.get_channel(1101419135398842388)
    time = {"s": 1, "m": 60, "h": 3600, "d": 86400}
    duration_seconds = int(duration[:-1]) * time[duration[-1]]
    await member.add_roles(role)
    await member.remove_roles(role1)
    await channel.send(f"Из {member.mention} сделали {role.name} на {duration}, по причине {reason}!")
    await asyncio.sleep(duration_seconds)
    await member.remove_roles(role)
    await member.add_roles(role1)
    await channel.send(f"{role.name} был сделан из {member.mention}!")

ошибка:
AttributeError: 'NoneType' object has no attribute 'id'

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

Traceback (most recent call last):
  File "C:\Users\dubey\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\ext\commands\bot.py", line 1350, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\dubey\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\ext\commands\core.py", line 1023, in invoke
    await injected(*ctx.args, **ctx.kwargs)  # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\dubey\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\ext\commands\core.py", line 238, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'id'
2023-05-26 20:32:50 ERROR    discord.ext.commands.bot Ignoring exception in command mute
Traceback (most recent call last):
  File "C:\Users\dubey\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\ext\commands\core.py", line 229, in wrapped
    ret = await coro(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\dubey\PycharmProjects\pythonProject2\main.py", line 327, in mute
    duration_seconds = int(duration[:-1]) * time[duration[-1]]
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\dubey\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\member.py", line 1044, in add_roles
    await req(guild_id, user_id, role.id, reason=reason)
                                 ^^^^^^^
AttributeError: 'NoneType' object has no attribute 'id'

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

Traceback (most recent call last):
  File "C:\Users\dubey\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\ext\commands\bot.py", line 1350, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\dubey\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\ext\commands\core.py", line 1023, in invoke
    await injected(*ctx.args, **ctx.kwargs)  # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\dubey\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\ext\commands\core.py", line 238, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'id'

Помогите пожалуйста новичку!
  • Вопрос задан
  • 82 просмотра
Пригласить эксперта
Ответы на вопрос 1
@Grefin_193
import discord
from discord.ext import commands
import asyncio
|
@bot.command()
@commands.has_guild_permissions(administrator=True)
async def mute(ctx, member: discord.Member, duration: str, reason):
guild = bot.get_guild(975494474098679869)
role = guild.get_role(975494474480369721)
channel = guild.get_channel(975494474719461431)
time = {"s": 1, "m": 60, "h": 3600, "d": 86400}
duration_seconds = int(duration[:-1]) * time[duration[-1]]
await member.add_roles(role)
await channel.send(f"Из {member.mention} сделали {role.name} на {duration}, по причине {reason}!")
await asyncio.sleep(duration_seconds)
await member.remove_roles(role)
await channel.send(f"{role.name} был сделан из {member.mention}!")

Этот код работает и в pycharm и в Visual studio Code
Ответ написан
Комментировать
Ваш ответ на вопрос

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

Войти через центр авторизации
Похожие вопросы