Ошибка в коде disnake

passwords = open("codes.txt", "r")
password1 = passwords.readline()
passwords.close()

import disnake
from disnake.ext import commands


users = [639713374992597024, 653252704117981185, 1013463398073257996, 686994022971342898]

bot = commands.Bot(command_prefix=".", help_command=None, intents=disnake.Intents.all(),
                   test_guilds=[1122189705459531786])


@bot.event
async def on_ready():
    print(f"Bot {bot.user} is ready to work!")





@bot.slash_command()
async def codes(inter, password):
    print(password + password1)
    if str(password) == str(password1):
        for ID in users:
            user = bot.get_user(ID)
            await member.send("проль: тест")
            await inter.send("Код отправлен: " + user.name)
    else:
        await inter.send("Пароль неверный.")

bot.run("секрет")

Ошибка: Ignoring exception in slash command 'codes': Traceback (most recent call last): File "C:\Users\User\AppData\Roaming\Python\Python311\site-packages\disnake\ext\commands\slash_core.py", line 728, in invoke await call_param_func(self.callback, inter, self.cog, **kwargs) File "C:\Users\User\AppData\Roaming\Python\Python311\site-packages\disnake\ext\commands\params.py", line 1083, in call_param_func return await maybe_coroutine(safe_call, function, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\User\AppData\Roaming\Python\Python311\site-packages\disnake\utils.py", line 567, in maybe_coroutine return await value ^^^^^^^^^^^ File "C:\Users\User\Desktop\crach-bot.py", line 29, in codes await member.send("проль: тест") ^^^^^^ NameError: name 'member' is not defined

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

Traceback (most recent call last): File "C:\Users\User\AppData\Roaming\Python\Python311\site-packages\disnake\ext\commands\interaction_bot_base.py", line 1378, in process_application_commands await app_command.invoke(interaction) File "C:\Users\User\AppData\Roaming\Python\Python311\site-packages\disnake\ext\commands\slash_core.py", line 737, in invoke raise CommandInvokeError(exc) from exc disnake.ext.commands.errors.CommandInvokeError: Command raised an exception: NameError: name 'member' is not defined


Ignoring exception in slash command 'codes': Traceback (most recent call last): File "C:\Users\User\AppData\Roaming\Python\Python311\site-packages\disnake\ext\commands\slash_core.py", line 728, in invoke await call_param_func(self.callback, inter, self.cog, **kwargs) File "C:\Users\User\AppData\Roaming\Python\Python311\site-packages\disnake\ext\commands\params.py", line 1083, in call_param_func return await maybe_coroutine(safe_call, function, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\User\AppData\Roaming\Python\Python311\site-packages\disnake\utils.py", line 567, in maybe_coroutine return await value ^^^^^^^^^^^ File "C:\Users\User\Desktop\crach-bot.py", line 70, in codes await user.send("пароль: тест") ^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'send'

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

Traceback (most recent call last): File "C:\Users\User\AppData\Roaming\Python\Python311\site-packages\disnake\ext\commands\interaction_bot_base.py", line 1378, in process_application_commands await app_command.invoke(interaction) File "C:\Users\User\AppData\Roaming\Python\Python311\site-packages\disnake\ext\commands\slash_core.py", line 737, in invoke raise CommandInvokeError(exc) from exc disnake.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'send'

Теперь пишет эту ошибку


Ответы (1 шт):

Автор решения: SuperFeda

В коде ошибки же ясно сказано: NameError: name 'member' is not defined. Значит переменной member нету и нужно ее создать, либо использовать существующий вариант.

Попробуйте этот код:

@bot.slash_command()
async def codes(inter, password):
    print(password + password1)
    if str(password) == str(password1):
        for ID in users:
            user = bot.get_user(ID)
            await user.send("пароль: тест")
            await inter.send("Код отправлен: " + user.name)
    else:
        await inter.send("Пароль неверный.")
→ Ссылка