forked from viveksantayana/geas-bot
27 lines
1.2 KiB
Python
27 lines
1.2 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 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 dev import configFile, yaml_load, yaml_dump
|
||
|
|
||
|
##### Actions for the bot to take whenever there is a new role deleted.
|
||
|
|
||
|
class on_guild_role_delete(commands.Cog):
|
||
|
def __init__(self, client):
|
||
|
self.client = client
|
||
|
|
||
|
@commands.Cog.listener()
|
||
|
async def on_guild_role_delete(self, role):
|
||
|
conf = yaml_load(configFile)
|
||
|
#### Bot will only respond if the role is not a bot-managed role, and the role is an admin role
|
||
|
if role.id in conf[str(role.guild.id)]['adminroles']:
|
||
|
conf[str(role.guild.id)]['adminroles'].remove(role.id)
|
||
|
yaml_dump(conf, configFile)
|
||
|
#### If the role is one of the Admin roles and is deleted, updates the bot's config to delete that role, preventing unnecessary roles from accumulating.
|
||
|
|
||
|
def setup(client):
|
||
|
client.add_cog(on_guild_role_delete(client))
|