Experimental Discord bot written in Python
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

generalcog.py 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. from discord.ext import commands
  2. from cogs.basecog import BaseCog, BotMessage
  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. f'{CONFIG["warning_emoji"]} No warning channel set!',
  26. mention_author=False)
  27. else:
  28. bm = BotMessage(
  29. context.guild,
  30. f'Test warning message (requested by {context.author.name})',
  31. type=BotMessage.TYPE_MOD_WARNING)
  32. await self.post_message(bm)
  33. @commands.command(
  34. brief='Simple test reply',
  35. )
  36. async def hello(self, context):
  37. await context.message.reply(
  38. f'Hey, {context.author.name}!',
  39. mention_author=False)
  40. @commands.command(
  41. brief='Shuts down the bot (admin only)',
  42. )
  43. @commands.has_permissions(administrator=True)
  44. @commands.guild_only()
  45. async def shutdown(self, context):
  46. await self.bot.close()