-
Notifications
You must be signed in to change notification settings - Fork 2
/
bot.py
49 lines (36 loc) · 1.59 KB
/
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import discord
from discord.ext import commands,tasks
import wavelink
from wavelink.ext import spotify
import os
import config
# Get the API token from the .env file.
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
class Bot(commands.Bot):
def __init__(self) -> None:
# contain bot features, like type, message, guild
intents = discord.Intents.all()
intents.message_content = True
# connect to discord server and init bot command features
super().__init__(intents=intents, command_prefix='!')
async def on_ready(self) -> None:
await self.load_cog()
await self.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name="!help"))
print(f'Bot is ready! Logged in as {self.user}')
async def load_cog(self):
for pyfile in os.listdir("./cogs"):
if pyfile.endswith(".py"):
await bot.load_extension(f'cogs.{pyfile[:-3]}')
print(f'Load moduel {pyfile[:-3]} successfully')
async def setup_hook(self) -> None:
# Wavelink 2.0 has made connecting Nodes easier... Simply create each Node
# and pass it to NodePool.connect with the client/bot.
sc = spotify.SpotifyClient(
client_id='6d793485170f46749e32ce46ad3da004',
client_secret='214b8f17a448431a8ca1bde6c25e72be'
)
node: wavelink.Node = wavelink.Node(uri='http://127.0.0.1:2333', password='youshallnotpass')
await wavelink.NodePool.connect(client=self, nodes=[node], spotify=sc)
if __name__ == "__main__":
bot = Bot()
bot.run(config.DISCORD_TOKEN)