import discord, json, os, random, re import collections from discord.ext import commands from setup.logger import LOGGER from setup.config import Config class InsultsCog(commands.Cog): def __init__(self, bot:discord.Bot): self.bot = bot with open(os.path.join(Config.CONFIG_PATH, "insults.txt")) as f: self.insults = [l.strip() for l in f.readlines()] @commands.Cog.listener() async def on_message(self, message:discord.Message): if len(message.content.split()) > 3: author = message.author if any(author.id == u.id for u in self.men): r = int(random.random()*100) print(r) if r < 5: insult = random.choice(self.insults) await message.reply(insult) @commands.Cog.listener() async def on_ready(self): self.men:list[discord.Member] = [] for guild in self.bot.guilds: for role in guild.roles: if re.match(r'^([hH]im|[hH]e).*$',role.name): self.men.extend(role.members) self.men = list(set(self.men))