-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
66 lines (46 loc) · 1.89 KB
/
main.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, tasks
import os
import random
with open('token.txt', 'r') as file:
TOKEN = file.read()
FKK_CHANNEL_ID = 942191175975190528
AFK_CHANNEL_ID = 848348815861743616
AUDIO_FOLDER = 'audio'
intents = discord.Intents.default()
intents.voice_states = True
bot = commands.Bot(command_prefix='!', intents=intents)
def getRandomAudioFile():
audio_files = os.listdir(AUDIO_FOLDER)
return AUDIO_FOLDER + '/' + random.choice(audio_files)
@bot.event
async def on_ready():
print(f'{bot.user.name} has connected to Discord!')
channel = bot.get_channel(FKK_CHANNEL_ID)
if channel:
print(f'Bot will play audio in channel: {channel.name}')
play_audio.start(channel)
else:
print(f'Channel with ID {FKK_CHANNEL_ID} not found. Please check the channel ID.')
@tasks.loop(seconds=1)
async def play_audio(channel):
voice_channel = discord.utils.get(bot.voice_clients, guild=channel.guild)
if voice_channel is None or not voice_channel.is_connected():
voice_channel = await channel.connect()
if not voice_channel.is_playing():
voice_channel.play(discord.FFmpegPCMAudio(getRandomAudioFile()),
after=lambda e: print(f'Error: {e}') if e else None)
@bot.event
async def on_voice_state_update(member, before, after):
if after.channel and after.channel.id == AFK_CHANNEL_ID:
# Replace 'TARGET_CHANNEL_ID' with the ID of the channel where you want to move the user
target_channel = bot.get_channel(FKK_CHANNEL_ID)
if target_channel:
await member.move_to(target_channel)
print(f'{member.name} moved from {after.channel.name} to {target_channel.name}')
else:
print(f'Target channel with ID {FKK_CHANNEL_ID} not found. Please check the channel ID.')
@bot.event
async def on_disconnect():
play_audio.stop()
bot.run(TOKEN)