Skip to content

Instantly share code, notes, and snippets.

@nonchris
Created March 29, 2022 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nonchris/4ab2aa168e79775d1c2a4cbeed715d5d to your computer and use it in GitHub Desktop.
Save nonchris/4ab2aa168e79775d1c2a4cbeed715d5d to your computer and use it in GitHub Desktop.
A quick d.py fix if your reaction role bot f*cked up
import discord
from discord.ext import commands
intents = discord.Intents.all()
bot = commands.Bot(command_prefix="!", intents=intents)
@bot.event
async def on_ready():
"""!
function called when the bot is ready. Emits the '[Bot] has connected' message
"""
print()
member_count = 0
guild_string = ""
for g in bot.guilds:
guild_string += f"{g.name} - {g.id} - Members: {g.member_count}\n"
member_count += g.member_count
print(f"Bot '{bot.user.name}' has connected, active on {len(bot.guilds)} guilds:\n{guild_string}")
# map emote sting to role ID
roles = {
"๐Ÿ“ˆ": 957323389163425873,
"๐Ÿ“Š": 957323915628265472,
"๐Ÿค–": 957323971349585980,
"๐Ÿ–ฅ๏ธ": 957323983630528574,
"๐Ÿงฎ": 957324766086320128,
"๐ŸŽฒ": 957324106016120842,
"๐Ÿšช": 957324848403742750,
"๐Ÿง‘โ€๐Ÿ’ป": 957324101834407986,
"๐Ÿง‘โ€๐Ÿ”ฌ": 957324096830574612,
"๐Ÿ”’": 957324104770416751,
"๐Ÿ”": 957324562637406260,
"๐Ÿ’ก": 957324564201889863,
"๐Ÿง ": 957324104367743026,
"๐Ÿ‘€": 958317022767353856,
"๐Ÿ“–": 958320007752847421,
"๐Ÿ—บ๏ธ": 958320363723448320,
"๐Ÿ“": 958318738971717652,
"๐Ÿ“": 957324766379913227,
"๐ŸŽ›๏ธ": 957324564868776056,
"๐Ÿ—ƒ๏ธ": 958318186015621161,
"โŒ›": 958317755243855902,
"๐ŸŽจ": 957324106641055764,
"๐Ÿง‘โ€๐Ÿซ": 958419063724441620,
}
async def merge(message: discord.Message):
"""
:param message: The message to walk the reactions for
"""
to_add: set[discord.member] = set()
to_remove: set[discord.member] = set()
for reaction in message.reactions:
print(roles[reaction.emoji])
role: discord.Role = message.guild.get_role(roles[reaction.emoji])
print(f"ROLE: {role.name}")
# get set of people who reacted and those who have the role
reactors = set(await reaction.users().flatten())
member_set = set(role.members)
# get the members that are in the correct state (have role and do want the role)
correct_members = member_set.intersection(reactors)
# members who have the role bot don't have reacted
to_remove = member_set.difference(correct_members)
# members who reacted but don't have the role
to_add = reactors.difference(correct_members)
# print(f"{role.name} to add: {to_add}, to remove: {to_remove}")
# make corrections
for member in to_add:
print("Add")
await member.add_roles(role)
print(f"{member.name};{member.id}")
for member in to_remove:
print("Remove")
await member.remove_roles(role)
print(f"{member.name};{member.id}")
# dispatch the process
@commands.has_permissions(administrator=True)
@bot.command(name="correct", aliases=["c"])
async def fetch_message(ctx: commands.Context):
# get channel and messages
channel: discord.TextChannel = ctx.guild.get_channel(957322759015378944)
message1: discord.Message = await channel.fetch_message(958338416045588560)
message2: discord.Message = await channel.fetch_message(958338417270325248)
# let's go
await merge(message1)
await merge(message2)
bot.run("") # YOUR TOKEN HERE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment