Skip to content

Commit

Permalink
THIS IS F*CKIN SLASH COMMANDS!!1!!!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
TiDurak committed Mar 29, 2023
1 parent 05568bb commit 1e783a3
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 5 deletions.
4 changes: 4 additions & 0 deletions cogs/listeners.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from rich import print
from config import settings


class ErrorListener(commands.Cog):
def __init__(self, bot):
self.bot = bot
Expand All @@ -23,12 +24,15 @@ async def on_command_error(self, ctx, error):
else:
raise error


class OnReady(commands.Cog):
def __init__(self, bot):
self.bot = bot

@commands.Cog.listener()
async def on_ready(self):
await self.bot.tree.sync()

print('[b green] Bot is ready! Just type d.help to see all bot commands.')
while True:
activity = random.choice(settings['activities'])
Expand Down
64 changes: 64 additions & 0 deletions cogs/slash.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from config import settings

import discord
from discord import app_commands
from discord.ext import commands
from googletrans import Translator


class Slash(commands.Cog):
"""Основные слэш-команды"""

def __init__(self, bot):
self.bot = bot

@app_commands.command(name="echo", description="Выводит текст от лица бота")
@app_commands.describe(message="Твоё сообщение, которое я напишу за тебя")
async def echo(self, interaction: discord.Interaction, message: str):
await interaction.response.send_message(message)

@app_commands.command(name="poll", description="ГАЛАСАВАНИЕ")
@app_commands.describe(question="Задай тему голосования",
option1="Первый вариант ответа (обязательно)",
option2="Второй вариант ответа",
option3="Третий варик",
option4="Ну ты понял короче")
async def poll(self, interaction: discord.Interaction,
question: str, option1: str, option2: str=None,
option3: str="None", option4: str="None", option5: str="None",
option6: str="None", option7: str="None", option8: str="None"):

options_template = [option1, option2, option3,
option4, option5, option6,
option7, option8]

options = []
for opt in options_template:
if opt is not "None":
options.append(opt)

if len(options) < 1:
await interaction.response.send_message('❌ Для создания голосования нужно хотя-бы 1 ответ!')
return

reactions_template = ['1⃣', '2⃣', '3⃣', '4⃣', '5⃣', '6⃣', '7⃣', '8⃣', '9⃣', '🔟']
reactions = []
for emoji in range(len(options)):
reactions.append(reactions_template[emoji])

description = []
for x, option in enumerate(options):
description += '\n{} {}'.format(reactions[x], option)

embed = discord.Embed(color=0xffcd4c,
title=f'{self.bot.get_emoji(settings["emojis"]["stonks"])} {interaction.user}: {question}',
description=''.join(description))

await interaction.response.send_message(embed=embed)
react_message = await interaction.original_response()
for reaction in reactions[:len(options)]:
await react_message.add_reaction(reaction)


async def setup(bot):
await bot.add_cog(Slash(bot))
5 changes: 2 additions & 3 deletions cogs/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from googletrans import Translator
from config import settings


class Text(commands.Cog):
def __init__(self, bot):
self.bot = bot
Expand All @@ -26,14 +27,11 @@ async def translate(self, ctx, lang, *, text):
title = "❌ Указан неверный язык!",
description = warntext))


@commands.command()
async def echo(self, ctx, *, arg):
await ctx.message.delete()
await ctx.send(arg)



@commands.command()
async def poll(self, ctx, question, *options: str):
lowercase = [opts.lower() for opts in options]
Expand Down Expand Up @@ -63,5 +61,6 @@ async def poll(self, ctx, question, *options: str):
embed.set_footer(text= f'Poll ID: {react_message.id} \nКстати! Вопрос нужно указывать в кавычках!' )
await react_message.edit(embed=embed)


async def setup(bot):
await bot.add_cog(Text(bot))
7 changes: 5 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from cogs import converters, fun, help, moderation, information, music, listeners, text
from cogs import converters, fun, help, moderation, information, music, listeners, text, slash
from config import settings
import sys
import asyncio

from rich import print

from discord import Intents
from discord import Intents, app_commands
from discord.ext import commands

print(f'[b yellow]Python {sys.version}')
Expand Down Expand Up @@ -40,6 +40,9 @@
asyncio.run(text.setup(bot))
print('[blue]text.py file has been loaded!')

asyncio.run(slash.setup(bot))
print('[blue]slash.py file has been loaded!')

print('[b i blue]All cogs has been loaded. Starting...')

bot.run(settings['token'])

0 comments on commit 1e783a3

Please sign in to comment.