Advertisement
EpicShardGamingYT

Untitled

Jun 13th, 2018
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.24 KB | None | 0 0
  1. # basic cog
  2. import discord
  3. from discord.ext import commands
  4.  
  5.  
  6. """A simple cog example with simple commands. Some with the use of events in cogs.
  7. Rewrite docs:
  8. http://dischttp://discordpy.readthedocs.io/en/rewrite/
  9. You could also create your own custom checks. Check out:
  10. https://github.com/Rapptz/discord.py/blob/master/discord/ext/commands/core.py#L689
  11. For a list of events:
  12. http://discordpy.readthedocs.io/en/rewrite/api.html#event-reference
  13. http://discordpy.readthedocs.io/en/rewrite/ext/commands/api.html#event-reference
  14. """
  15.  
  16.  
  17. class Simple:
  18.     """Some simple commands for the rewrite cog"""
  19.  
  20.     def __init__(self, bot):
  21.         self.bot = bot
  22.  
  23.     @commands.command(name='repeat', aliases=['copy', 'mimic'])
  24.     async def do_repeat(self, ctx, *, our_input: str):
  25.         """A simple command which repeats our input.
  26.        In rewrite Context is automatically passed to our commands as the first argument after self."""
  27.  
  28.         await ctx.send(our_input)
  29.  
  30.     @commands.command(name='add', aliases=['plus'])
  31.     @commands.guild_only()
  32.     async def do_addition(self, ctx, first: int, second: int):
  33.         """A simple command which does addition on two integer values."""
  34.  
  35.         total = first + second
  36.         await ctx.send(f'The sum of **{first}** and **{second}**  is  **{total}**')
  37.  
  38.     @commands.command(name='embeds')
  39.     @commands.guild_only()
  40.     async def example_embed(self, ctx):
  41.         """A simple command which showcases the use of embeds.
  42.        Try changing colors and names etc."""
  43.  
  44.         embed = discord.Embed(title='Example Embed',
  45.                               description='Showcasing the use of Embeds...\nSee the visualizer for more info.',
  46.                               colour=0x98FB98)
  47.         embed.set_author(name='GeorgeCY',
  48.                          url='https://gist.github.com/MysterialPy/public',
  49.                          icon_url='https://www.w3schools.com/w3css/w3css_images.asp')
  50.         embed.set_image(url='https://www.google.no/imgres?imgurl=https%3A%2F%2Fthemeawesome.com%2Fthemes%2Ftotalpress%2Fwp-content%2Fuploads%2F2012%2F12%2Funicorn-wallpaper.jpg&imgrefurl=https%3A%2F%2Fthemeawesome.com%2Fthemes%2Ftotalpress%2Fpost-format-image%2F&docid=a0UGZeBM_0JzLM&tbnid=ZPIb9IX5WOejGM%3A&vet=10ahUKEwjGy8-56dDbAhXBKJoKHVccA_0QMwhnKA4wDg..i&w=1600&h=1200&bih=974&biw=1920&q=image&ved=0ahUKEwjGy8-56dDbAhXBKJoKHVccA_0QMwhnKA4wDg&iact=mrc&uact=8')
  51.        
  52.         embed.set_footer(text='Made in Python with discord.py@rewrite', icon_url='http://i.imgur.com/5BFecvA.png')
  53.  
  54.         await ctx.send(content='**A simple Embed for discord.py@rewrite in cogs.**', embed=embed)
  55.  
  56.     async def on_member_ban(self, guild, user):
  57.         """Event Listener which is called when a user is banned from the guild.
  58.        This will print some stuff into the console
  59.        """
  60.  
  61.         print(f'{user.name}-{user.id} was banned from {guild.name}-{guild.id}')
  62.  
  63. # The setup fucntion below is neccesarry. Remember we give bot.add_cog() the name of the class in this case Simple.
  64. # When we load the cog, we use the name of the file.
  65. # Remember to have the bot parameter, and run the bot.add_cog.
  66. # You could have the cog inside the main file just with bot.add_cog(ClassName(bot)).
  67. def setup(bot):
  68.     bot.add_cog(Simple(bot))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement