''' DOBAVIT ON MEMBER JOIN ZAKONCHITS MAGAZIN ''' import random import disnake # Подключаем библиотеку from disnake.ext import commands intents = disnake.Intents.default() # Подключаем "Разрешения" intents.message_content = True intents.reactions = True # Задаём префикс и интенты bot = commands.Bot(command_prefix='?', intents=intents) bot.players = {} bot.shop_items = { 'fanta': 200, } def player_add_money(user_id, money): bot.players[user_id]['balance'] = bot.players[user_id]['balance'] + money def player_remove_money(user_id, money): bot.players[user_id]['balance'] = bot.players[user_id]['balance'] - money def create_player(user_id, money): bot.players[user_id] = { "balance": money, "inventory": {} } print(f'Created {bot.players[user_id]}') def clear_embed(): bot.embed = disnake.Embed(colour=disnake.Colour.random()) @bot.event async def on_command_error(ctx, error): if isinstance(error, commands.CommandOnCooldown): clear_embed() embed = bot.embed.add_field(name="Error :(", value='Wait %.2fs before doing this again...' % error.retry_after) await ctx.send(embed=embed) commands.check() raise error # re-raise the error so all the errors will still show up in console async def on_member_join(member): await member.send(f"{member.display_name} joined!") @bot.before_invoke async def common(ctx): bot.embed = disnake.Embed(colour=disnake.Colour.random()) @bot.command() async def start(ctx): await ctx.send('бот готов к работе') @bot.command() async def Bal(ctx): if ctx.author.id in bot.players: reply = f'У вас монет:{bot.players[ctx.author.id]["balance"]}' else: create_player(ctx.author.id, 0) reply = f'У вас монет: {bot.players[ctx.author.id]["balance"]}' embed = bot.embed.add_field(name=f"{ctx.author}", value=reply) await ctx.send(embed=embed) @commands.cooldown(1, 5.0, commands.BucketType.user) @bot.command() async def Work(ctx): work_money = random.randint(100, 200) if ctx.author.id in bot.players: reply = f'Вы заработали: {work_money}' player_add_money(ctx.author.id, work_money) else: create_player(ctx.author.id, work_money) reply = f'Вы заработали: {work_money}' embed = bot.embed.add_field(name="Misha-Work", value=reply) await ctx.send(embed=embed) @bot.command() async def Shop(ctx): output = "" for key, value in bot.shop_items.items(): output = output + f"\n Item: {key} | Price: {value}" embed = bot.embed.add_field(name="Misha-Market", value=output) await ctx.reply(embed=embed) message = await bot.wait_for("message") if message.content in bot.shop_items: purchase = message.content clear_embed() embed = bot.embed.add_field(name="Misha-Market", value=f"Вы действительно хотите купить {purchase}") await ctx.send( embed=embed, components=[ disnake.ui.Button(label="Yes", style=disnake.ButtonStyle.success, custom_id="yes"), disnake.ui.Button(label="No", style=disnake.ButtonStyle.danger, custom_id="no"), ],) @bot.listen("on_button_click") async def help_listener(inter: disnake.MessageInteraction): if inter.component.custom_id not in ["yes", "no"]: return if inter.component.custom_id == "yes": buyer = inter.author.id try: if bot.players[buyer]["balance"] >= bot.shop_items[purchase]: if purchase in bot.players[buyer]["inventory"]: bot.players[buyer]["inventory"][purchase] += 1 else: bot.players[buyer]["inventory"][purchase] = 1 else: await inter.response.send_message("No money! Go !Work") except KeyError: await inter.response.send_message("У вас нет акаунта в банке") elif inter.component.custom_id == "no": await inter.response.send_message("Got it. Signing off!") return @bot.event async def on_ready(): print(f'We have logged in as {bot.user}') bot.run('TOKEN')