✨ Fully converted to slash commands
This commit is contained in:
@ -1,28 +1,29 @@
|
||||
import discord, traceback
|
||||
from discord.ext import commands
|
||||
|
||||
class EventCog(commands.cog):
|
||||
def __init__(bot):
|
||||
class EventCog(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
|
||||
# Sets the game and logs when the bot logs in
|
||||
@client.event
|
||||
async def on_ready():
|
||||
logThis("Logged in as "+client.user.name+", "+str(client.user.id))
|
||||
game = discord.Game("Some weeb shit")
|
||||
await client.change_presence(activity=game)
|
||||
@commands.Cog.listener()
|
||||
async def on_ready(self):
|
||||
self.bot.log("Logged in as "+self.bot.user.name+", "+str(self.bot.user.id))
|
||||
game = discord.Game("Use /help for commands")
|
||||
await self.bot.change_presence(activity=game)
|
||||
|
||||
# Logs when user sends a command
|
||||
@client.event
|
||||
async def on_slash_command(ctx):
|
||||
logThis(f"{ctx.author.display_name} ran {ctx.name}")
|
||||
@commands.Cog.listener()
|
||||
async def on_slash_command(self, ctx):
|
||||
self.bot.log(f"{ctx.author.display_name} ran /{ctx.name}")
|
||||
|
||||
# Logs if a command experiences an error
|
||||
@client.event
|
||||
async def on_slash_command_error(ctx, error):
|
||||
@commands.Cog.listener()
|
||||
async def on_slash_command_error(self, 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.channel_id))
|
||||
self.bot.log(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__)
|
||||
@ -32,5 +33,8 @@ class EventCog(commands.cog):
|
||||
exception = exception[:index]
|
||||
|
||||
exceptionString = "".join(exception)
|
||||
logThis([f"exception in {ctx.name} command", f"{exceptionString}"],str(ctx.channel_id), 40)
|
||||
await ctx.send("Something went wrong (error code 000)")
|
||||
self.bot.log([f"exception in /{ctx.name}", f"{exceptionString}"],str(ctx.channel_id), 40)
|
||||
await ctx.send("Something went wrong (error code 000)")
|
||||
|
||||
def setup(bot):
|
||||
bot.add_cog(EventCog(bot))
|
||||
|
Reference in New Issue
Block a user