-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
43 lines (34 loc) · 1.16 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
from asyncio.tasks import Task
from logging import error
import discord
import os
import random
from discord.ext import tasks, commands
TOKEN = input("Enter your Discord Bot token.")
guildID = input("Enter the ID of the guild which you'd like to automate banner switching")
PREFIX = '!'
INTENTS = discord.Intents.default()
bot = commands.Bot(command_prefix=PREFIX, intents=INTENTS)
bot.remove_command('help')
class Loops(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.rotateBanners.start()
def cog_unload(self):
self.rotateBanners.cancel()
@tasks.loop(minutes = 15)
async def rotateBanners(self):
try:
guild = bot.get_guild(358708716599508993)
newBanner = open(os.getcwd()+"\\banners\\"+(random.choice(os.listdir(os.getcwd()+"\\banners"))), "rb")
await guild.edit(banner = newBanner.read())
newBanner.close()
except Exception as e:
print(e)
except discord.errors.HTTPException as e:
print(e)
@bot.event
async def on_ready():
print("Ready. Logged in as: " + bot.user.name)
bot.add_cog(Loops(bot))
bot.run(TOKEN)