-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbot.py
34 lines (26 loc) · 977 Bytes
/
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
import os
import discord
# Load environment variables from .env file
from dotenv import load_dotenv
load_dotenv()
# Initialize the bot
intents = discord.Intents.default()
intents.message_content = True
bot = discord.Client(intents=intents)
# Channel ID to send notifications
CHANNEL_ID = int(os.environ['CHANNEL_ID'])
VOICE_CHANNEL_ID = int(os.environ['VOICE_CHANNEL_ID'])
@bot.event
async def on_ready():
print(f"Logged in as {bot.user.name} ({bot.user.id})")
@bot.event
async def on_voice_state_update(member, before, after):
# Check if the member joins a specific voice channel
if not before.channel and after.channel and after.channel.id == VOICE_CHANNEL_ID:
# Get the text channel by ID
channel = bot.get_channel(CHANNEL_ID)
if channel:
# Send a notification message
await channel.send(f"{member.name} has joined voice channel: "+ after.channel.name)
# Run Bot with Token
bot.run(os.environ['BOT_TOKEN'])