Add presence with guilds count

This commit is contained in:
norohind 2022-03-28 23:53:41 +03:00
parent 9976bfded5
commit 56f698f410
Signed by: norohind
GPG Key ID: 01C3BECC26FB59E1

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import discord
from discord.ext import commands from discord.ext import commands, tasks
from discord.ext.commands import Context from discord.ext.commands import Context
import datetime import datetime
import time import time
@ -10,6 +10,7 @@ class BotInformation(commands.Cog):
def __init__(self, bot: commands.Bot): def __init__(self, bot: commands.Bot):
self.bot: commands.Bot = bot self.bot: commands.Bot = bot
self.start_time: float = time.time() self.start_time: float = time.time()
self.presence_task.start()
@commands.command('info') @commands.command('info')
async def get_info(self, ctx: Context): async def get_info(self, ctx: Context):
@ -31,6 +32,15 @@ Invite link: https://discord.com/oauth2/authorize?client_id={self.bot.user.id}&s
uptime_str = datetime.timedelta(seconds=int(uptime)) uptime_str = datetime.timedelta(seconds=int(uptime))
await ctx.send(f"Application is up for {str(uptime_str)}") await ctx.send(f"Application is up for {str(uptime_str)}")
@tasks.loop(seconds=120)
async def presence_task(self) -> None:
presence = discord.Game(f"{len(self.bot.guilds)} guilds | @{self.bot.user.name} help")
await self.bot.change_presence(activity=presence)
@presence_task.before_loop
async def presence_task_wait_ready(self):
await self.bot.wait_until_ready()
async def setup(bot): async def setup(bot):
await bot.add_cog(BotInformation(bot)) await bot.add_cog(BotInformation(bot))