-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
85 lines (59 loc) · 2.36 KB
/
run.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
import config
import discord
import config
import os
from discord.ext import commands
from musicbot.audiocontroller import AudioController
from musicbot.settings import Settings
from musicbot import utils
from musicbot.utils import guild_to_audiocontroller, guild_to_settings
from musicbot.commands.general import General
initial_extensions = ['musicbot.commands.music',
'musicbot.commands.general', 'musicbot.plugins.button']
bot = commands.Bot(command_prefix=config.BOT_PREFIX,
pm_help=True, case_insensitive=True)
if __name__ == '__main__':
config.ABSOLUTE_PATH = os.path.dirname(os.path.abspath(__file__))
config.COOKIE_PATH = config.ABSOLUTE_PATH + config.COOKIE_PATH
if config.BOT_TOKEN == "":
print("Error: No bot token!")
exit
for extension in initial_extensions:
try:
bot.load_extension(extension)
except Exception as e:
print(e)
@bot.event
async def on_ready():
print(config.STARTUP_MESSAGE)
await bot.change_presence(status=discord.Status.online, activity=discord.Game(name="Music, type {}help".format(config.BOT_PREFIX)))
for guild in bot.guilds:
await register(guild)
print("Joined {}".format(guild.name))
print(config.STARTUP_COMPLETE_MESSAGE)
@bot.event
async def on_guild_join(guild):
print(guild.name)
await register(guild)
async def register(guild):
guild_to_settings[guild] = Settings(guild)
guild_to_audiocontroller[guild] = AudioController(bot, guild)
sett = guild_to_settings[guild]
await guild.me.edit(nick=sett.get('default_nickname'))
if config.GLOBAL_DISABLE_AUTOJOIN_VC == True:
return
vc_channels = guild.voice_channels
if sett.get('vc_timeout') == False:
if sett.get('start_voice_channel') == None:
try:
await guild_to_audiocontroller[guild].register_voice_channel(guild.voice_channels[0])
except Exception as e:
print(e)
else:
for vc in vc_channels:
if vc.id == sett.get('start_voice_channel'):
try:
await guild_to_audiocontroller[guild].register_voice_channel(vc_channels[vc_channels.index(vc)])
except Exception as e:
print(e)
bot.run(config.BOT_TOKEN, bot=True, reconnect=True)