diff --git a/bot.py b/bot.py index 23dddb7..a60d9f3 100644 --- a/bot.py +++ b/bot.py @@ -1,4 +1,5 @@ from discord.ext import commands +from discord import app_commands import discord import os import asyncio @@ -16,9 +17,23 @@ async def load(): if filename.endswith(".py"): await client.load_extension(f"cogs.{filename[:-3]}") +async def slashload(): + for filename in os.listdir("./slashcogs"): + if filename.endswith(".py"): + await client.load_extension(f"slashcogs.{filename[:-3]}") + +@client.command() +async def sync(ctx): + if ctx.message.author.id == 262672220260663297: + await client.tree.sync(guild=discord.Object(id=1100149380763373608)) + print('Command tree synced.') + else: + await ctx.send('You must be the botowner to use this command!') + async def main(): async with client: await load() + await slashload() await client.start(discordtoken.get()) asyncio.run(main()) \ No newline at end of file diff --git a/slashcogs/slashping.py b/slashcogs/slashping.py new file mode 100644 index 0000000..d0b5743 --- /dev/null +++ b/slashcogs/slashping.py @@ -0,0 +1,20 @@ +import discord +from discord.ext import commands +from discord import app_commands + +class SlashPing(commands.Cog): + def __init__(self, client): + self.client = client + + @commands.Cog.listener() + async def on_ready(self): + print("SlashPing.py is ready") + + @app_commands.command(name="ping", description="Gives the bot latency in ms.") + async def slashping(self, interaction: discord.Interaction): + bot_latency = round(self.client.latency * 1000) + await interaction.response.send_message(f"pong! {bot_latency}ms.") + + +async def setup(client): + await client.add_cog(SlashPing(client)) \ No newline at end of file diff --git a/slashcogs/slashroll.py b/slashcogs/slashroll.py new file mode 100644 index 0000000..700c5f5 --- /dev/null +++ b/slashcogs/slashroll.py @@ -0,0 +1,44 @@ +import discord +from discord import app_commands +from discord.ext import commands +import random + +class SlashRoll(commands.Cog): + def __init__(self, client): + self.client = client + + @commands.Cog.listener() + async def on_ready(self): + print("SlashRoll.py is ready") + + @app_commands.command(name="roll", description="Rolls a number between 1 and 100 with a rating") + async def slashroll(self, interaction: discord.Interaction): + rolled = random.randint(1,100) + rating = "" + + if(rolled == 100): + rating = "What a chad" + elif(rolled < 100 and rolled > 90): + rating = "Almost" + elif(rolled <= 90 and rolled > 80): + rating = "Good" + elif(rolled <= 80 and rolled > 69): + rating = "Alright" + elif(rolled == 69): + rating = "Nice" + elif(rolled < 69 and rolled > 50): + rating = "Decent" + elif(rolled <= 50 and rolled > 25): + rating = "Meh" + elif(rolled <= 25 and rolled > 1): + rating = "Bad" + elif(rolled == 1): + rating = "LOL" + + message = "You rolled " + str(rolled) + ", " + rating + + await interaction.response.send_message(message) + + +async def setup(client): + await client.add_cog(SlashRoll(client)) \ No newline at end of file