-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
92 lines (71 loc) · 2.07 KB
/
bot.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import os
import random
from dotenv import load_dotenv
from discord.ext import commands
import discord
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
intents = discord.Intents.default()
intents.members = True
bot = commands.Bot(command_prefix='/', intents=intents)
@bot.event
async def on_ready():
print(f'{bot.user.name} has connected to Discord!')
@bot.command(name='99')
async def nine_nine(ctx):
brooklyn_99_quotes = [
'I\'m the human form of the 💯 emoji.',
'Bingpot!',
(
'Cool. Cool cool cool cool cool cool cool, '
'no doubt no doubt no doubt no doubt.'
),
]
response = random.choice(brooklyn_99_quotes)
await ctx.send(response)
@bot.event
async def on_raw_reaction_add(payload: discord.RawReactionActionEvent):
if payload.message_id != 851685610925588490:
return
emoji_to_role = {
discord.PartialEmoji(name='🔴'): 851685230477574165, # ID of the role associated with unicode emoji '🔴'.
}
guild = bot.get_guild(payload.guild_id)
if guild is None:
return
try:
role_id = emoji_to_role[payload.emoji]
except KeyError:
return
role = guild.get_role(role_id)
if role is None:
return
try:
await payload.member.add_roles(role)
except discord.HTTPException:
pass
@bot.event
async def on_raw_reaction_remove(payload: discord.RawReactionActionEvent):
if payload.message_id != 851685610925588490:
return
emoji_to_role = {
discord.PartialEmoji(name='🔴'): 851685230477574165, # ID of the role associated with unicode emoji '🔴'.
}
guild = bot.get_guild(payload.guild_id)
if guild is None:
return
try:
role_id = emoji_to_role[payload.emoji]
except KeyError:
return
role = guild.get_role(role_id)
if role is None:
return
member = guild.get_member(payload.user_id)
if member is None:
return
try:
await member.remove_roles(role)
except discord.HTTPException:
pass
bot.run(TOKEN)