from discord.ext import commands
import json
intents = discord.Intents.all()
bot = commands.Bot(command_prefix='!', intents=intents)
try:
with open("roles_with_income.json", "r") as file:
roles_with_income = json.load(file)
except FileNotFoundError:
roles_with_income = {}
except json.JSONDecodeError:
print("Ошибка при декодировании данных JSON.")
money_emoji = "?"
@bot.event
async def on_ready():
print(f'{bot.user.name} подключился к Discord!')
@bot.event
async def on_command_error(ctx, error):
await ctx.send(f'Произошла ошибка: {error}')
@bot.command()
async def role_income(ctx):
if not roles_with_income:
embed = discord.Embed(title="Роли экономики", description="Список ролей экономики пуст.", color=discord.Color.blue())
await ctx.send(embed=embed)
else:
embed = discord.Embed(title="Роли экономики", description="Управляйте вашим доходом от ролей экономики на панели управления", color=discord.Color.blue())
for index, (role_id, income) in enumerate(roles_with_income.items(), start=1):
role = ctx.guild.get_role(int(role_id))
if role:
embed.add_field(name=f"{index} - {role.mention} | {income} {money_emoji} каждый час", value=" ", inline=False)
await ctx.send(embed=embed)
@bot.command()
async def role_income_add(ctx, role: discord.Role, income: int):
if role.id in roles_with_income:
await ctx.send("Эта роль уже добавлена.")
else:
roles_with_income[str(role.id)] = income
save_data()
await ctx.send(f"Роль '{role.mention}' успешно добавлена с доходом {income} {money_emoji} каждый час.")
@bot.command()
async def role_income_remove(ctx, role_number: int):
if role_number <= 0 or role_number > len(roles_with_income):
await ctx.send("Неверный номер роли.")
else:
role_id = list(roles_with_income.keys())[role_number - 1]
role = ctx.guild.get_role(int(role_id))
if role:
del roles_with_income[role_id]
save_data()
await ctx.send(f"Роль '{role.mention}' успешно удалена из списка.")
else:
await ctx.send("Ошибка: роль не найдена.")
def save_data():
with open("roles_with_income.json", "w") as f:
json.dump(roles_with_income, f)```