Vivek Santayana
78bc73c023
Completed channel group of config subcommands Fixed bugs in config initialisation function
33 lines
1.3 KiB
Python
33 lines
1.3 KiB
Python
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 bot import configFile, yaml_load, yaml_dump
|
|
|
|
### Cog for handling the non-Slash prefix for native Bot commands.
|
|
|
|
class Prefix(commands.Cog, name='Server Command Prefix'):
|
|
def __init__(self, client):
|
|
self.client = client
|
|
|
|
#### 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
|
|
|
|
@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)
|
|
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\nNote: This will not affect /commands.```")
|
|
|
|
def setup(client):
|
|
client.add_cog(Prefix(client)) |