This repository has been archived by the owner on Nov 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevents.py
55 lines (50 loc) · 1.72 KB
/
events.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
import discord
from config import bot
from utils import add_channel_roles, remove_channel_roles
from discord.ext.commands import is_owner
@bot.event
async def on_ready():
print("Bot is ready")
# set the bot status to "Ping @voice_vhannel_name"
await bot.change_presence(
activity=discord.Activity(
type=discord.ActivityType.listening, name="@voice_channel_name"
)
)
@bot.event
# when someone joins a voice channel
async def on_voice_state_update(member, before, after):
"""Different cases:
1. Member joins a voice channel:
- Add the channel roles to the member
2. Member leaves a voice channel:
- Remove the channel roles from the member
3. Member switches voice channels:
- Remove the channel roles from the member for the old channel
- Add the channel roles to the member for the new channel
4. Member mutes/, or any change that dosen't change the voice channel id
- Do nothing
"""
if before.channel is None:
# Case 1
await add_channel_roles(after.channel, member)
elif after.channel is None:
# Case 2
await remove_channel_roles(before.channel, member)
elif before.channel.id != after.channel.id:
# Case 3
await remove_channel_roles(before.channel, member)
await add_channel_roles(after.channel, member)
else:
# Case 4
pass
@bot.command()
@is_owner()
async def shutdown(ctx):
await ctx.respond("Shutting down...", ephemeral=True)
await bot.change_presence(status=discord.Status.invisible)
@bot.command()
@is_owner()
async def shutup(ctx):
await ctx.respond("Shutting up...", ephemeral=True)
await bot.change_presence(status=discord.Status.online)