-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreactrole.py
66 lines (52 loc) · 2.25 KB
/
reactrole.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import discord
from discord.ext import commands
import json
class React(commands.Cog):
def __init__(self, client):
self.client = client
self.react_messages = [875602307033739285,
875602205804216321, 875601733819187240]
# Add react
@commands.command(aliases=['ar'])
async def addreact(self, ctx, message: discord.Message, emoji):
if message != None and emoji != None:
await message.add_reaction(emoji)
else:
await ctx.send("Invalid argument.")
# Add bundles react
@commands.command(aliases=['ab'])
async def add_bundles_react(self, ctx, message: discord.Message, *emoji):
if message != None and emoji != None:
for emote in emoji:
await message.add_reaction(emote)
else:
await ctx.send("Invalid argument.")
# React role
@commands.Cog.listener("on_raw_reaction_add")
async def add_role(self, payload):
if int(payload.message_id) in self.react_messages:
guild_id = payload.guild_id
guild = discord.utils.find(
lambda g: g.id == guild_id, self.client.guilds)
with open("reactrole.json") as f:
data = json.load(f)
for info in data:
if info["emoji"] == payload.emoji.name:
role = discord.utils.get(
guild.roles, name=info["role"])
await payload.member.add_roles(role)
@commands.Cog.listener("on_raw_reaction_remove")
async def remove_role(self, payload):
if int(payload.message_id) in self.react_messages:
guild_id = payload.guild_id
guild = discord.utils.find(
lambda g: g.id == guild_id, self.client.guilds)
with open("reactrole.json") as f:
data = json.load(f)
for info in data:
if info["emoji"] == payload.emoji.name:
role = discord.utils.get(
guild.roles, name=info["role"])
await self.client.get_guild(payload.guild_id).get_member(payload.user_id).remove_roles(role)
def setup(client):
client.add_cog(React(client))