2021-07-15 22:54:09 +01:00
import yaml # YAML parser for Bot config files
import asyncio # Discord Py Dependency
import discord # Main Lib
from discord . ext import commands # Commands module
2021-07-15 23:13:01 +01:00
from bot import configFile , yaml_load , yaml_dump
2021-07-15 22:54:09 +01:00
### Cog for handling the non-Slash prefix for native Bot commands.
2021-07-16 23:53:31 +01:00
class Prefix ( commands . Cog , name = ' Server Command Prefix ' ) :
2021-07-15 22:54:09 +01:00
def __init__ ( self , client ) :
self . client = client
2021-07-17 13:56:04 +01:00
#### Check if user is an administrator
async def cog_check ( self , ctx ) :
for role in ctx . author . roles :
if role . permissions . administrator :
return True
return ctx . author . guild_permissions . administrator
2021-07-15 22:54:09 +01:00
@commands.command (
name = ' changeprefix ' ,
aliases = [ ' prefix ' ] ,
description = ' This command changes the prefix string for the native, non-slash command functionality of the bot. Defaults to `-`. It does not affect the workings of /commands. ' ,
brief = ' Changes the bot prefix. '
)
async def _changePrefix ( self , ctx , prefix : str = ' - ' ) :
conf = yaml_load ( configFile )
conf [ str ( ctx . guild . id ) ] [ ' prefix ' ] = prefix . lower ( )
yaml_dump ( conf , configFile )
2021-07-17 13:56:04 +01:00
await ctx . send ( f " ``` { self . client . user . name } ' s prefix for native bot commands has been changed to ` { prefix } ` for the guild ` { ctx . guild . name } `. \n \n Note: This will not affect /commands.``` " )
2021-07-15 22:54:09 +01:00
def setup ( client ) :
client . add_cog ( Prefix ( client ) )