Я начал переходить с обычных команд на слэш команды, но тут у меня начались проблемы с ctx...
Ошибка:
An exception has occurred while executing command `collect-income`:
Traceback (most recent call last):
File "C:\Users\egorl\AppData\Local\Programs\Python\Python38\lib\site-packages\discord_slash\client.py", line 1352, in invoke_command
await func.invoke(ctx, **args)
File "C:\Users\egorl\AppData\Local\Programs\Python\Python38\lib\site-packages\discord_slash\model.py", line 209, in invoke
return await self.func(self.cog, *args, **kwargs)
File "D:\discord_bot-msb\pycommands\economy-commands\collect-income.py", line 74, in collect_income
if discord.utils.find(lambda r: r.name == f"{roles.NACHINAYUSHCHIY_SKUPSHCHIK_NAME}", ctx.message.guild.roles) in user.roles:
AttributeError: 'NoneType' object has no attribute 'guild'
Код:
@commands.Cog.listener()
async def on_ready(self):
print(
f"""- Команда collect-income загружена."""
)
@cog_ext.cog_slash(
name = "collect-income",
description = "Собрать зарплату, доход с ролей."
)
@commands.cooldown(1, 14400, commands.BucketType.user)
async def collect_income(self, ctx):
users = await get_bank_data()
user = ctx.author
users[str(user.id)]["wallet"] = users[str(user.id)]["wallet"]
await open_account(self, user)
embed = discord.Embed(
colour = 0xC9FF00
)
embed.set_author(
name = user.name,
icon_url = user.avatar_url
)
# Начинающий скупщик
if discord.utils.find(lambda r: r.name == f"{roles.NACHINAYUSHCHIY_SKUPSHCHIK_NAME}", ctx.message.guild.roles) in user.roles:
await ctx.reply(
embed = discord.Embed(
title = f"""ERROR""",
description = f"""У вас, т.е. у скупщиков нету зарплаты.""",
colour = 0xFF0000
)
)
return
...
await ctx.reply(embed = embed)
Использую библиотеки:
discord-py-interactions==3.0.2
discord.py==1.7.3