Started writing /commands.
Completed channel group of config subcommands Fixed bugs in config initialisation function
This commit is contained in:
		@@ -16,7 +16,10 @@ class on_command_error(commands.Cog, name='On Command Error'):
 | 
			
		||||
	@commands.Cog.listener()
 | 
			
		||||
	async def on_command_error(self, ctx, error):
 | 
			
		||||
		if isinstance(error, discord.DiscordException):
 | 
			
		||||
			if isinstance(error, commands.CheckFailure):
 | 
			
		||||
			if isinstance(error, commands.CommandNotFound):
 | 
			
		||||
				print(f'Error: User {ctx.author.name}#{ctx.author.discriminator} / {ctx.author.display_name} entered an invalid command <{ctx.message.clean_content}> in the guild {ctx.guild.name}.')
 | 
			
		||||
				await ctx.reply(f'```Error: This is not a valid command.```')
 | 
			
		||||
			elif isinstance(error, commands.CheckFailure):
 | 
			
		||||
				print(f'Error: User {ctx.author.name}#{ctx.author.discriminator} / {ctx.author.display_name} is not authorised to issue the command <{ctx.command.name}> in the guild {ctx.guild.name}.')
 | 
			
		||||
				await ctx.reply(f'```Error: You are not authorised to issue this command.```')
 | 
			
		||||
			else:
 | 
			
		||||
 
 | 
			
		||||
@@ -7,7 +7,7 @@ from discord_slash import SlashCommand, SlashContext, cog_ext, utils			# Slash C
 | 
			
		||||
from discord_slash.utils.manage_commands import create_choice, create_option	# Slash Command features
 | 
			
		||||
import logging
 | 
			
		||||
# logger and handler
 | 
			
		||||
from bot import checkConfig, clearConfig, configFile, parseConfigCheck, setConfig, yaml_dump, yaml_load
 | 
			
		||||
from bot import checkConfig, clearConfig, configFile, parseConfigCheck, setConfig, yaml_dump, yaml_load, loadCogs, unloadCogs
 | 
			
		||||
 | 
			
		||||
#### Actions for the Bot to take once it is ready to interact with commands.
 | 
			
		||||
class on_ready(commands.Cog, name='On Ready Events'):
 | 
			
		||||
@@ -17,6 +17,9 @@ class on_ready(commands.Cog, name='On Ready Events'):
 | 
			
		||||
	@commands.Cog.listener()
 | 
			
		||||
	async def on_ready(self):
 | 
			
		||||
 | 
			
		||||
		async def test(self):
 | 
			
		||||
			await self.client.get_channel(865348933022515220).send('Foo')
 | 
			
		||||
 | 
			
		||||
		#### Create any missing config entries for guilds
 | 
			
		||||
		for guild in self.client.guilds:
 | 
			
		||||
			setConfig(guild)
 | 
			
		||||
@@ -32,6 +35,12 @@ class on_ready(commands.Cog, name='On Ready Events'):
 | 
			
		||||
			conf = yaml_load(configFile)
 | 
			
		||||
			if not status:
 | 
			
		||||
				await guild.get_channel(conf[str(guild.id)]['channels']['mod']).send(f"```The Bot's configurations are incomplete for the guild `{guild.name}`. Some limited functions will still be available, but most features cannot be used until the configurations are complete.\n{parseConfigCheck(output)}\nYou can set these configuration values using the `/config` command.```")
 | 
			
		||||
		
 | 
			
		||||
		# #### Reload the /commands after the configs have finished loading.
 | 
			
		||||
		# unloadCogs('slashcommands')
 | 
			
		||||
		# loadCogs('slashcommands')
 | 
			
		||||
 | 
			
		||||
		await test(self)
 | 
			
		||||
 | 
			
		||||
def setup(client):
 | 
			
		||||
	client.add_cog(on_ready(client))
 | 
			
		||||
							
								
								
									
										36
									
								
								app/cogs/events/on_slash_command_error.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								app/cogs/events/on_slash_command_error.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,36 @@
 | 
			
		||||
import yaml								# YAML parser for Bot config files
 | 
			
		||||
import asyncio							# Discord Py Dependency
 | 
			
		||||
import discord							# Main Lib
 | 
			
		||||
from discord.ext import commands		# Commands module
 | 
			
		||||
from discord_slash import SlashCommand, SlashContext, cog_ext, utils			# Slash Command Library
 | 
			
		||||
from discord_slash.utils.manage_commands import create_choice, create_option	# Slash Command features
 | 
			
		||||
import logging
 | 
			
		||||
# logger and handler
 | 
			
		||||
from bot import configFile, yaml_load, yaml_dump
 | 
			
		||||
 | 
			
		||||
#### Error Handler Event Listener for Slash Command Errors
 | 
			
		||||
class on_slash_command_error(commands.Cog, name='On Command Error'):
 | 
			
		||||
	def __init__(self, client):
 | 
			
		||||
		self.client = client
 | 
			
		||||
 | 
			
		||||
	@commands.Cog.listener()
 | 
			
		||||
	async def on_slash_command_error(self, ctx:SlashContext, error):
 | 
			
		||||
		if isinstance(error, Exception):
 | 
			
		||||
			await ctx.send(
 | 
			
		||||
				content='```Invalid Command: {error}```',
 | 
			
		||||
				tts=True,
 | 
			
		||||
				hidden=True,
 | 
			
		||||
				delete_after=10,				
 | 
			
		||||
			)
 | 
			
		||||
			# if isinstance(error, commands.CommandNotFound):
 | 
			
		||||
			# 	print(f'Error: User {ctx.author.name}#{ctx.author.discriminator} / {ctx.author.display_name} entered an invalid command <{ctx.message.clean_content}> in the guild {ctx.guild.name}.')
 | 
			
		||||
			# 	await ctx.reply(f'```Error: This is not a valid command.```')
 | 
			
		||||
			# elif isinstance(error, commands.CheckFailure):
 | 
			
		||||
			# 	print(f'Error: User {ctx.author.name}#{ctx.author.discriminator} / {ctx.author.display_name} is not authorised to issue the command <{ctx.command.name}> in the guild {ctx.guild.name}.')
 | 
			
		||||
			# 	await ctx.reply(f'```Error: You are not authorised to issue this command.```')
 | 
			
		||||
			# else:
 | 
			
		||||
			# 	print(f'User {ctx.author.name}#{ctx.author.discriminator} / {ctx.author.display_name} received error: "{error}" when attempting to issue command <{ctx.command.name}> in the guild {ctx.guild.name}.')
 | 
			
		||||
			# 	await ctx.reply(f'```Error: {error}```')
 | 
			
		||||
 | 
			
		||||
def setup(client):
 | 
			
		||||
	client.add_cog(on_slash_command_error(client))
 | 
			
		||||
		Reference in New Issue
	
	Block a user