Untitled
unknown
python
2 years ago
6.7 kB
8
Indexable
import disnake
import asyncio
import discord
from disnake.ext import commands
from disnake import Button, ButtonStyle
bot = commands.Bot(command_prefix="/", intents=disnake.Intents.all())
def has_specific_role():
async def predicate(ctx):
required_role = disnake.utils.get(ctx.guild.roles, name="DS Manager") # Замените на имя вашей роли
if required_role in ctx.author.roles:
return True
else:
await ctx.send("You don't have permission to run this command.", ephemeral=True)
return False
return commands.check(predicate)
# Слэш-команда /помощь
@bot.slash_command(
name="помощь", # или "help", как вам удобнее
description="показать список доступных команд и их примеры использования",
)
async def help_command(ctx):
help_embed = disnake.Embed(
title="Помощь",
description="Вот список доступных команд и примеры их использования:",
color=disnake.Color.green()
)
help_embed.add_field(
name="/айди",
value="Получение ID пользователей, имеющих указанную роль.\nПример: `/айди имя_роли:DS manager`",
inline=False
)
help_embed.add_field(
name="/лс_1/2/3",
value="Отправка сообщения в ЛС пользователям с указанными ID из файла.\nПример: `/лс_1/2/3 имя_файла:ID.txt текст:капт`",
inline=False
)
help_embed.add_field(
name="/реакции",
value="Получение ID пользователей, которые оставили определенную реакциию на сообщение.\nПример: `/реакции сообщение:ID_сообщения реакция:🍪`",
inline=False
)
help_embed.add_field(
name="/список_войс",
value="Получение ID пользователей, которые находятся в голосовом канале.\nПример: `/список_войс канал: #🐺〡Волчья нора #1`",
inline=False
)
await ctx.send(embed=help_embed, ephemeral=True) # ephemeral=True делает сообщение видимым только для пользователя
# CREATING LIST
user_data = {}
@bot.slash_command(
name="список",
description="Создание списка пользователей.",
options=[
disnake.Option("type", "Тип списка (MCL или FW)", type=disnake.OptionType.string, choices=["MCL", "FW"], required=True),
disnake.Option("start_time", "Время начала", type=disnake.OptionType.string, required=True),
disnake.Option("color", "Цвет", type=disnake.OptionType.string, required=True)
]
)
@has_specific_role()
async def список(ctx, type: str, start_time: str, color: str):
# Преобразуем переменную time в целое число
start_time = int(start_time)
voice_time = start_time - 1
# Create message for list
message_content = (
f"**{type} Время начала {start_time}:00 / Voice {voice_time}:00**\n"
f"Цвет - **{color}**\n\n"
"**MAIN**\n\n"
"**RESERVE**\n\n"
)
# Create buttons
message = await ctx.send(message_content,
components = [
disnake.ui.Button(label="➕", style=disnake.ButtonStyle.grey),
disnake.ui.Button(label="🚑", style=disnake.ButtonStyle.green),
disnake.ui.Button(label="🔁", style=disnake.ButtonStyle.blurple),
disnake.ui.Button(label="❌", style=disnake.ButtonStyle.red),
])
# Create buttons
message = await ctx.send(message_content,
components = [
disnake.ui.Button(label="➕", style=disnake.ButtonStyle.grey),
disnake.ui.Button(label="🚑", style=disnake.ButtonStyle.green),
disnake.ui.Button(label="🔁", style=disnake.ButtonStyle.blurple),
disnake.ui.Button(label="❌", style=disnake.ButtonStyle.red),
])
# Read and create file, which have: voice_time, start_time and color save in data
with open('data.txt', 'r') as data_file:
data = data_file.readlines()
# Write file
with open('data.txt', 'w') as data_file:
data_file.writelines([type, start_time, color])
# Get data from file
with open('data.txt', 'r') as data_file:
data = data_file.readlines()
voice_time = data[0]
start_time = data[1]
color = data[2]
def save_data(data, file_path):
with open(file_path, 'w') as f:
f.writelines(data)
@bot.listen("on_button_click")
async def help_listener(inter: disnake.MessageInteraction):
# Read and create file, which have: voice_time, start_time and color save in data
with open('data.txt', 'r') as data_file:
data = data_file.readlines()
# Get data from file
with open('data.txt', 'r') as data_file:
data = data_file.readlines()
voice_time = data[0]
start_time = data[1]
color = data[2]
if data is None:
await inter.response.send_message("Data not found. Please create a list first.", ephemeral=True)
return
voice_time, start_time, color = data
if inter.component.custom_id not in ["➕", "🚑", "🔁", "❌"]:
# We filter out any other button presses except
# the components we wish to process.
return
if inter.component.custom_id == "➕":
# Изменяем message_content для "➕"
message_content = (
f"**{type} Время начала {start_time}:00 / Voice {voice_time}:00**\n"
f"Цвет - **{color}**\n\n"
f"**MAIN**\n"
f"**НОВЫЙ ЧЕЛ**\n\n"
f"**RESERVE**\n"
)
await inter.response.send_message("You succesfly added in list!", ephemeral=True)
# await inter.edit_original_message(content=message_content)
# Start
@bot.event
async def on_ready():
print(f"{bot.user} online and working!")
game = disnake.Game("Eating cookies 🍪 and /помощь")
await bot.change_presence(status=disnake.Status.online, activity=game)
token = open('DISCORD_BOT_SECRET.env', 'r').readline()
bot.run(token)Editor is loading...