I'm currently a hosting discord bot on Heroku, and it has been working fine. But a problem with Heroku, is that I only have about 500 free hosting hours (I can't remember the exact number). That's slightly annoying for me, since I use the bot to run suggestion channels. And whenever someone says something in the suggestion channel while the bot is offline, there is no response from the bot (the bot is supposed to delete the user's message and send it again in embed).
The solution I found is to create a command to close the suggestion channel when the bot is about to go offline. I've been doing this as well for a long time, until one day, I forgot to turn it off. Then, everyone was sending messages in the suggestion channel without knowing what is happening. So now, I would like to know if there is a way to make the bot run the channel closing command before it goes offline. Here is the command for closing the channel:
@commands.command(aliases=['close-server'])
@commands.is_owner()
async def closeserver(self, ctx):
if ctx.guild.id != 735105735792394251:
return
await ctx.channel.purge(limit=1)
for user in ctx.guild.members:
member = discord.utils.get(ctx.guild.roles, name='Member')
bot_offline = discord.utils.get(ctx.guild.roles, name='Bot Currently Offline')
if member in user.roles:
await user.add_roles(bot_offline)
else:
not_verified = discord.utils.get(ctx.guild.roles, name='Not_Verified')
await user.add_roles(not_verified)
await user.remove_roles(member)
announcements = self.bot.get_channel(735106648330469488)
await announcements.send('**___`The server Is closed`___**')
And this is the command to re-open the channel:
@commands.command(aliases=['open-server'])
@commands.is_owner()
async def openserver(self, ctx):
if ctx.guild.id != 735105735792394251:
return
await ctx.channel.purge(limit=1)
for user in ctx.guild.members:
member = discord.utils.get(ctx.guild.roles, name='Member')
bot_offline = discord.utils.get(ctx.guild.roles, name='Bot Currently Offline')
if bot_offline in user.roles:
await user.add_roles(member)
else:
not_verified = discord.utils.get(ctx.guild.roles, name='Not_Verified')
await user.remove_roles(not_verified)
await user.remove_roles(bot_offline)
announcements = self.bot.get_channel(735106648330469488)
await announcements.send('**___`The server Is opened`___**')
Using my current script to close and open the server, what should I do?