async def on_raw_reaction_add(self, payload): if str(payload.emoji) == "тнР": m = await self.bot.get_channel(payload.channel_id).fetch_message(payload.message_id) amt = len(await discord.utils.get(m.reactions, emoji=str(payload.emoji)).users().flatten()) if amt > 2: data = superutils.fs() a = "" for atch in m.attachments: a += "\n" + atch.url if str(m.id) in data["messages"]: h = await discord.utils.get(m.guild.text_channels, name="hall-of-fame").fetch_message(data["messages"][str(m.id)]) await h.edit(content="тнР " + m.author.mention + " has a post in the Hall of Fame! " + str(amt) + " stars and counting... тнР" + ("\n\n" + m.content if m.content != "" else m.content) + "\n" + a) else: msg = await discord.utils.get(m.guild.text_channels, name="hall-of-fame").send("тнР " + m.author.mention + " has a post in the Hall of Fame! " + str(amt) + " star" + ("s" if amt > 1 else "") + " and counting... тнР" + ("\n\n" + m.content if m.content != "" else m.content) + "\n" + a) data["messages"][str(m.id)] = msg.id superutils.fs(data)
async def add(self, ctx, *, content): if len(content) < 32: return await ctx.channel.send("Please offer a suggestion at least 32 characters in length, to explain the context of the suggestion.") data = superutils.fs() if not str(ctx.guild.id) in data["suggestions"]: data["suggestions"][str(ctx.guild.id)] = {} e = discord.Embed(title=("Suggestion #" + str(len(data["suggestions"][str(ctx.guild.id)]) + 1)), description=content, colour=0x5f7d4e) e.set_thumbnail(url=ctx.author.avatar_url) e.add_field(name="This suggestion is open!", value="Please vote on it and share your thoughts in <#555440421149474829>!") #channel mention for whatever channel you would let people discuss suggestions in. e.set_author(name=str(ctx.author),icon_url=ctx.author.avatar_url) msg = await discord.utils.get(ctx.guild.channels, name="suggestions_box").send(embed=e) #another channel where the suggestions will actually appear. await msg.add_reaction("👍") await msg.add_reaction("👎") data["suggestions"][str(ctx.guild.id)][("#" + str(len(data["suggestions"][str(ctx.guild.id)]) + 1))] = {"id":msg.id, "outcome":"open", "response":""} superutils.fs(data) await ctx.message.delete()
async def on_raw_reaction_remove(self, payload): if str(payload.emoji) == "тнР": m = await self.bot.get_channel(payload.channel_id).fetch_message(payload.message_id) data = superutils.fs() try: h = await discord.utils.get(m.guild.text_channels, name="hall-of-fame").fetch_message(data["messages"][str(m.id)]) except KeyError: print("Disregard reaction remove, the message does not exist in the Hall of Fame.") else: amt = len(await discord.utils.get(m.reactions, emoji=str(payload.emoji)).users().flatten()) a = "" for atch in m.attachments: a += "\n" + atch.url if amt > 2: await h.edit(content="тнР " + m.author.mention + " has a post in the Hall of Fame! " + str(amt) + " star" + ("s" if amt > 1 else "") + " and counting... тнР" + ("\n\n" + m.content if m.content != "" else m.content) + "\n" + a) else: await h.delete() del data["messages"][str(m.id)] superutils.fs(data)
async def respond(self, ctx, number, outcome, *, response = None): if not ctx.author.guild_permissions.manage_messages: return await ctx.channel.send("You do not have the applicable permissions to use this command!") try: data = superutils.fs() msg = await discord.utils.get(ctx.guild.channels, name="suggestions_box").fetch_message(data["suggestions"][str(ctx.guild.id)][("#" + number)]["id"]) except: return await ctx.channel.send(number + " does not seem to be a valid suggestion index.") outcomes = {"approve": {"response":"has been approved:", "colour": 0x00cc00},"deny": {"response":"has been denied:", "colour": 0xcc0000},"existing": {"response":"has already been addressed:", "colour": 0xff6600},"duplicate": {"response":"has already been submitted:", "colour": 0x9900cc},"inappropriate": {"response":"was considered inappropriate:", "colour": 0x990000},"reopen": {"response":"is open!", "colour": 0x5f7d4e}} if not outcome.lower() in outcomes: return await ctx.channel.send("\"" + outcome.capitalize() + "\" does not seem to be a valid suggestion closure type.") if outcome != "reopen" and (response is None or len(response) < 32): return await ctx.channel.send("Please offer a reason at least 32 characters in length, to explain the context of the desired outcome.") e = msg.embeds[0] e.colour = outcomes[outcome.lower()]["colour"] e.set_field_at(0, name=("The suggestion " + outcomes[outcome.lower()]["response"]), value="Please vote on it and share your thoughts in <#555440421149474829>!" if response is None else response) await msg.edit(embed=e) data["suggestions"][str(ctx.guild.id)][("#" + number)]["outcome"] = "open" if outcome == "reopen" else outcome data["suggestions"][str(ctx.guild.id)][("#" + number)]["response"] = "" if response is None else response superutils.fs(data)
async def edit(self, ctx, number, *, content): try: data = superutils.fs() msg = await discord.utils.get(ctx.guild.channels, name="suggestions_box").fetch_message(data["suggestions"][str(ctx.guild.id)][("#" + number)]["id"]) except: return await ctx.channel.send(number + " does not seem to be a valid suggestion index.") e = msg.embeds[0] if e.author.name != str(ctx.author): return await ctx.channel.send("You cannot edit someone else's suggestion, only your own!") if data["suggestions"][str(ctx.guild.id)][("#" + number)]["outcome"] != "open": return await ctx.channel.send("Suggestion #" + number + " has already been closed. Please contact a staff member if you need to reopen the suggestion.") if len(content) < 32: return await ctx.channel.send("Please offer a suggestion at least 32 characters in length, to explain the context of the suggestion.") e.description = content await msg.edit(embed=e) await ctx.message.delete()
import discord import superutils from discord.ext import commands class Superintendent(commands.Bot): def __init__(self): super().__init__(command_prefix="))", case_insensitive=True) async def on_ready(self): superutils.load_extensions(self, False) print("\nInitialization complete -\n User: "******"\n ID: " + str(self.user.id)) if __name__ == "__main__": Superintendent().run(superutils.fs()["bot_token"])