umi/cogs/vcjoin.py

50 lines
1.4 KiB
Python
Raw Normal View History

2022-06-23 05:09:34 +00:00
import discord
from discord.ext.commands import Cog
from decouple import config
2022-06-23 05:09:34 +00:00
def setup(bot: discord.Bot):
bot.add_cog(VCJoin(bot))
class VCJoin(Cog):
"""Log when a member joins VC, for pinging purposes"""
CHANNEL: int = config("DISCORD_VCJOIN_CHANNEL", cast=int)
2022-06-23 05:09:34 +00:00
def __init__(self, bot: discord.Bot):
self.bot: discord.Bot = bot
self.channel: discord.TextChannel = self.bot.get_channel(VCJoin.CHANNEL)
print("Initialized VCJoin cog")
@Cog.listener()
async def on_ready(self):
await self.bot.wait_until_ready()
self.channel = self.bot.get_channel(VCJoin.CHANNEL)
@Cog.listener()
async def on_voice_state_update(
self,
member: discord.Member,
before: discord.VoiceState,
after: discord.VoiceState):
"""Log when someone joins or leaves VC"""
if before.channel == after.channel:
return
if not before.channel:
embed = discord.Embed(
description = f"**{member.display_name}** joined **{after.channel.name}**"
)
elif not after.channel:
embed = discord.Embed(
description = f"**{member.display_name}** left **{before.channel.name}**"
)
else:
embed = discord.Embed(
description = f"**{member.display_name}** moved from **{before.channel.name}** to **{after.channel.name}**"
)
embed = embed.set_author(
name = f"{member.display_name} ({member})",
icon_url = member.display_avatar.url,
)
msg = await self.channel.send(embed=embed)
if msg:
print(embed.description[2:-2])