Started work on converting all commands to slash-commands

This commit is contained in:
NikolajDanger
2021-03-29 00:55:31 +02:00
parent e6e6b9b9b9
commit 232f97d0c8
11 changed files with 363 additions and 179 deletions

View File

@ -1,10 +1,10 @@
import discord, os, finnhub, platform, asyncio, traceback
from discord.ext import commands
from discord_slash import SlashCommand
from pymongo import MongoClient
from funcs import logThis, makeFiles, Money, Funcs, SwChar, SwDestiny, SwRoll, Games, Generators, BedreNetflix, NerdShit
commandPrefix = "!"
from utils import Options
if platform.system() == "Windows":
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
@ -23,14 +23,6 @@ class Credentials():
self.radarrKey = data[6][15:].replace(" ","")
self.sonarrKey = data[7][15:].replace(" ","")
class Options():
def __init__(self):
with open("options.txt","r") as f:
data = f.read().splitlines()
self.prefix = data[0][7:].replace(" ","")
self.testing = (data[1][8:].replace(" ","").lower() == "true")
class Gwendolyn(commands.Bot):
def __init__(self):
self.options = Options()
@ -57,13 +49,15 @@ class Gwendolyn(commands.Bot):
self.money = Money(self)
self.funcs = Funcs(self)
super().__init__(command_prefix=commandPrefix, case_insensitive=True)
super().__init__(command_prefix=" ", case_insensitive=True)
# Creates the required files
makeFiles()
# Creates the Bot
client = Gwendolyn()
slash = SlashCommand(client, sync_commands=True, sync_on_cog_reload=True, override_type=True)
# Logs in
@client.event
@ -74,16 +68,16 @@ async def on_ready():
# Logs when user sends a command
@client.event
async def on_command(ctx):
logThis(f"{ctx.message.author.display_name} ran {ctx.message.content}")
async def on_slash_command(ctx):
logThis(f"{ctx.author.display_name} ran {ctx.name}")
# Logs if a command experiences an error
@client.event
async def on_command_error(ctx, error):
async def on_slash_command_error(ctx, error):
if isinstance(error, commands.CommandNotFound):
await ctx.send("That's not a command (error code 001)")
elif isinstance(error,commands.errors.MissingRequiredArgument):
logThis(f"{error}",str(ctx.message.channel.id))
logThis(f"{error}",str(ctx.channel_id))
await ctx.send("Missing command parameters (error code 002). Try using `!help [command]` to find out how to use the command.")
else:
exception = traceback.format_exception(type(error), error, error.__traceback__)
@ -93,7 +87,7 @@ async def on_command_error(ctx, error):
exception = exception[:index]
exceptionString = "".join(exception)
logThis([f"exception in command !{ctx.command}", f"{exceptionString}"],str(ctx.message.channel.id), 40)
logThis([f"exception in {ctx.name} command", f"{exceptionString}"],str(ctx.channel_id), 40)
await ctx.send("Something went wrong (error code 000)")
#Loads cogs