import discord
from discord.ext import commands
import os
bot = commands.Bot(command_prefix='/', intents=discord.Intents.all())
languages = {
'ua': 'Українська',
'ru': 'Русский',
'en': 'English'
}
@bot.event
async def on_ready():
print(f'{bot.user.name} is ready!')
channel = bot.get_channel(11203293912384712) # channel id
if channel:
await select_language(channel)
async def select_language(ctx):
buttons = []
for lang_code, lang_name in languages.items():
button = discord.ui.Button(style=discord.ButtonStyle.primary, label=lang_name)
button.custom_id = f'lang_{lang_code}'
buttons.append(button)
view = discord.ui.View()
for button in buttons:
view.add_item(button)
await ctx.send('Пожалуйста, выберите язык квеста:', view=view)
@bot.event
async def on_button_click(interaction):
button_id = interaction.data['custom_id']
lang_code = button_id.split('_')[1]
selected_language = languages.get(lang_code)
await welcome_message(interaction.channel, selected_language)
@bot.event
async def welcome_message(ctx, language):
if language == 'ru':
welcome_text = 'Добро пожаловать в квест!'
start_button_label = 'Начать'
elif language == 'ua':
welcome_text = 'Ласкаво просимо в квест!'
start_button_label = 'Почати'
elif language == 'en':
welcome_text = 'Welcome to the quest!'
start_button_label = 'Start'
else:
welcome_text = 'Welcome to the quest!'
start_button_label = 'Start'
view = discord.ui.View()
start_button = discord.ui.Button(style=discord.ui.ButtonStyle.primary, label=start_button_label)
start_button.custom_id = 'start_button'
view.add_item(start_button)
await ctx.send(welcome_text, view=view)
bot.run(os.getenv('TOKEN'))
@bot.event
async def on_button_click(interaction):
if interaction.custom_id.startswith('lang_'):
lang_code = interaction.custom_id.split('_')[1]
selected_language = languages.get(lang_code)
await welcome_message(interaction.channel, selected_language)
elif interaction.custom_id == 'start_button':
# Обработка нажатия кнопки "Начать"/"Почати"/"Start"
await interaction.channel.send("Вы нажали кнопку 'Начать'!")
# Остальной код оставьте без изменений.