Experimental Discord bot written in Python
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

generalcog.py 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. from discord.ext import commands
  2. from cogs.basecog import BaseCog
  3. from storage import ConfigKey, Storage
  4. class GeneralCog(BaseCog):
  5. def __init__(self, bot: commands.Bot):
  6. super().__init__(bot)
  7. self.is_connected = False
  8. self.is_ready = False
  9. @commands.Cog.listener()
  10. async def on_connect(self):
  11. print('on_connect')
  12. self.is_connected = True
  13. @commands.Cog.listener()
  14. async def on_ready(self):
  15. print('on_ready')
  16. self.is_ready = True
  17. @commands.command(
  18. brief='Posts a test warning in the configured warning channel.'
  19. )
  20. @commands.has_permissions(ban_members=True)
  21. @commands.guild_only()
  22. async def testwarn(self, context):
  23. if Storage.get_config_value(context.guild, ConfigKey.WARNING_CHANNEL_ID) is None:
  24. await context.message.reply(
  25. 'No warning channel set!',
  26. mention_author=False)
  27. else:
  28. await self.warn(context.guild,
  29. f'Test warning message (requested by {context.author.name})')
  30. @commands.command(
  31. brief='Simple test reply',
  32. )
  33. async def hello(self, context):
  34. await context.message.reply(
  35. f'Hey, {context.author.name}!',
  36. mention_author=False)
  37. @commands.command(
  38. brief='Shuts down the bot (admin only)',
  39. )
  40. @commands.has_permissions(administrator=True)
  41. @commands.guild_only()
  42. async def shutdown(self, context):
  43. await self.bot.close()