-
-
Save barbosso/efb21e4029aefc2043e38b90b88918c7 to your computer and use it in GitHub Desktop.
Revisions
-
EvieePy revised this gist
Mar 23, 2019 . 1 changed file with 1 addition and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -48,12 +48,7 @@ def get_prefix(bot, message): # Here we load our extensions(cogs) listed above in [initial_extensions]. if __name__ == '__main__': for extension in initial_extensions: bot.load_extension(extension) @bot.event async def on_ready(): -
EvieePy revised this gist
Mar 22, 2019 . 3 changed files with 5 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ from discord.ext import commands class MembersCog(commands.Cog): def __init__(self, bot): self.bot = bot This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ from discord.ext import commands class OwnerCog(commands.Cog): def __init__(self, bot): self.bot = bot This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,7 +16,7 @@ """ class SimpleCog(commands.Cog): """SimpleCog""" def __init__(self, bot): @@ -64,7 +64,8 @@ async def example_embed(self, ctx): embed.set_footer(text='Made in Python with discord.py@rewrite', icon_url='http://i.imgur.com/5BFecvA.png') await ctx.send(content='**A simple Embed for discord.py@rewrite in cogs.**', embed=embed) @commands.Cog.listener() async def on_member_ban(self, guild, user): """Event Listener which is called when a user is banned from the guild. For this example I will keep things simple and just print some info. -
EvieePy revised this gist
Dec 16, 2017 . 1 changed file with 13 additions and 13 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,6 @@ import sys, traceback """This is a multi file example showcasing many features of the command extension and the use of cogs. These are examples only and are not intended to be used as a fully functioning bot. Rather they should give you a basic understanding and platform for creating your own bot. @@ -25,7 +24,7 @@ def get_prefix(bot, message): """A callable Prefix for our bot. This could be edited to allow per server prefixes.""" # Notice how you can use spaces in prefixes. Try to keep them simple though. prefixes = ['>?', 'lol ', '!?'] @@ -37,14 +36,24 @@ def get_prefix(bot, message): # If we are in a guild, we allow for the user to mention us or use any of the prefixes in our list. return commands.when_mentioned_or(*prefixes)(bot, message) # Below cogs represents our folder our cogs are in. Following is the file name. So 'meme.py' in cogs, would be cogs.meme # Think of it like a dot path import initial_extensions = ['cogs.simple', 'cogs.members', 'cogs.owner'] bot = commands.Bot(command_prefix=get_prefix, description='A Rewrite Cog Example') # Here we load our extensions(cogs) listed above in [initial_extensions]. if __name__ == '__main__': for extension in initial_extensions: try: bot.load_extension(extension) except Exception as e: print(f'Failed to load extension {extension}.', file=sys.stderr) traceback.print_exc() @bot.event async def on_ready(): @@ -54,16 +63,7 @@ async def on_ready(): # Changes our bots Playing Status. type=1(streaming) for a standard game you could remove type and url. await bot.change_presence(game=discord.Game(name='Cogs Example', type=1, url='https://twitch.tv/kraken')) print(f'Successfully logged in and booted...!') bot.run('TOKEN', bot=True, reconnect=True) -
EvieePy revised this gist
Nov 2, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -30,7 +30,7 @@ def get_prefix(bot, message): prefixes = ['>?', 'lol ', '!?'] # Check to see if we are outside of a guild. e.g DM's etc. if not message.guild: # Only allow ? to be used in DMs return '?' -
EvieePy revised this gist
Oct 25, 2017 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -39,9 +39,9 @@ def get_prefix(bot, message): # Below cogs represents our folder our cogs are in. Following is the file name. So 'meme.py' in cogs, would be cogs.meme # Think of it like a dot path import initial_extensions = ['cogs.simple', 'cogs.members', 'cogs.owner'] bot = commands.Bot(command_prefix=get_prefix, description='A Rewrite Cog Example') -
EvieePy revised this gist
Oct 25, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -55,7 +55,7 @@ async def on_ready(): # Changes our bots Playing Status. type=1(streaming) for a standard game you could remove type and url. await bot.change_presence(game=discord.Game(name='Cogs Example', type=1, url='https://twitch.tv/kraken')) # Here we load our extensions(cogs) listed above in [initial_extensions]. if __name__ == '__main__': for extension in initial_extensions: try: -
EvieePy revised this gist
Sep 30, 2017 . 1 changed file with 4 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,21 +23,19 @@ """ def get_prefix(bot, message): """A callable Prefix for our bot. This could be edited to allow per server prefixes.""" # Notice how you can use spaces in prefixes. Try to keep them simple though. prefixes = ['>?', 'lol ', '!?'] # Check to see if we are outside of a guild. e.g DM's etc. if message.guild.id is None: # Only allow ? to be used in DMs return '?' # If we are in a guild, we allow for the user to mention us or use any of the prefixes in our list. return commands.when_mentioned_or(*prefixes)(bot, message) # Below cogs represents our folder our cogs are in. Following is the file name. So 'meme.py' in cogs, would be cogs.meme # Think of it like a dot path import -
EvieePy revised this gist
Sep 30, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -32,7 +32,7 @@ def get_prefix(b, m): prefixes = ['>?', 'lol ', '!?'] # Check to see if we are outside of a guild. e.g DM's etc. if m.guild.id is None: # Only allow ? to be used in DMs return '?' -
EvieePy revised this gist
Sep 30, 2017 . 1 changed file with 5 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,8 +23,10 @@ """ def get_prefix(b, m): """A callable Prefix for our bot. This could be edited to allow per server prefixes. b: bot m: message""" # Notice how you can use spaces in prefixes. Try to keep them simple though. prefixes = ['>?', 'lol ', '!?'] @@ -35,7 +37,7 @@ def get_prefix(bot, msg): return '?' # If we are in a guild, we allow for the user to mention us or use any of the prefixes in our list. return commands.when_mentioned_or(*prefixes)(b, m) # Below cogs represents our folder our cogs are in. Following is the file name. So 'meme.py' in cogs, would be cogs.meme # Think of it like a dot path import -
EvieePy revised this gist
Sep 22, 2017 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,10 +12,10 @@ async def joined(self, ctx, *, member: discord.Member): """Says when a member joined.""" await ctx.send(f'{member.display_name} joined on {member.joined_at}') @commands.command(name='coolbot') async def cool_bot(self, ctx): """Is the bot cool?""" await ctx.send('This bot is cool. :)') @commands.command(name='top_role', aliases=['toprole']) @commands.guild_only() -
EvieePy revised this gist
Aug 26, 2017 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,7 +10,7 @@ def __init__(self, bot): @commands.command(name='load', hidden=True) @commands.is_owner() async def cog_load(self, ctx, *, cog: str): """Command which Loads a Module. Remember to use dot path. e.g: cogs.owner""" try: @@ -23,7 +23,7 @@ async def cog_load(self, ctx, *, cog: str): @commands.command(name='unload', hidden=True) @commands.is_owner() async def cog_unload(self, ctx, *, cog: str): """Command which Unloads a Module. Remember to use dot path. e.g: cogs.owner""" try: @@ -36,7 +36,7 @@ async def cog_unload(self, ctx, *, cog: str): @commands.command(name='reload', hidden=True) @commands.is_owner() async def cog_reload(self, ctx, *, cog: str): """Command which Reloads a Module. Remember to use dot path. e.g: cogs.owner""" try: -
EvieePy revised this gist
Aug 26, 2017 . 2 changed files with 54 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -40,7 +40,8 @@ def get_prefix(bot, msg): # Below cogs represents our folder our cogs are in. Following is the file name. So 'meme.py' in cogs, would be cogs.meme # Think of it like a dot path import initial_extensions = ('cogs.simple', 'cogs.members', 'cogs.owner',) bot = commands.Bot(command_prefix=get_prefix, description='A Rewrite Cog Example') This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,52 @@ from discord.ext import commands class OwnerCog: def __init__(self, bot): self.bot = bot # Hidden means it won't show up on the default help. @commands.command(name='load', hidden=True) @commands.is_owner() async def cog_load(self, ctx, *, cog: str): """Loads a Module. Remember to use dot path. e.g: cogs.owner""" try: self.bot.load_extension(cog) except Exception as e: await ctx.send(f'**`ERROR:`** {type(e).__name__} - {e}') else: await ctx.send('**`SUCCESS`**') @commands.command(name='unload', hidden=True) @commands.is_owner() async def cog_unload(self, ctx, *, cog: str): """Unloads a Module. Remember to use dot path. e.g: cogs.owner""" try: self.bot.unload_extension(cog) except Exception as e: await ctx.send(f'**`ERROR:`** {type(e).__name__} - {e}') else: await ctx.send('**`SUCCESS`**') @commands.command(name='reload', hidden=True) @commands.is_owner() async def cog_reload(self, ctx, *, cog: str): """Reloads a Module. Remember to use dot path. e.g: cogs.owner""" try: self.bot.unload_extension(cog) self.bot.load_extension(cog) except Exception as e: await ctx.send(f'**`ERROR:`** {type(e).__name__} - {e}') else: await ctx.send('**`SUCCESS`**') def setup(bot): bot.add_cog(OwnerCog(bot)) -
EvieePy revised this gist
Aug 26, 2017 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -37,6 +37,8 @@ def get_prefix(bot, msg): # If we are in a guild, we allow for the user to mention us or use any of the prefixes in our list. return commands.when_mentioned_or(*prefixes)(bot, msg) # Below cogs represents our folder our cogs are in. Following is the file name. So 'meme.py' in cogs, would be cogs.meme # Think of it like a dot path import initial_extensions = ('cogs.simple', 'cogs.members',) -
EvieePy revised this gist
Aug 26, 2017 . 2 changed files with 6 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ from discord.ext import commands class MembersCog: def __init__(self, bot): self.bot = bot @@ -49,6 +49,7 @@ async def check_permissions(self, ctx, *, member: discord.Member=None): await ctx.send(content=None, embed=embed) # Thanks to Gio for the Command. # The setup fucntion below is neccesarry. Remember we give bot.add_cog() the name of the class in this case MembersCog. # When we load the cog, we use the name of the file. def setup(bot): bot.add_cog(MembersCog(bot)) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -78,6 +78,7 @@ async def on_member_ban(self, guild, user): print(f'{user.name}-{user.id} was banned from {guild.name}-{guild.id}') # The setup fucntion below is neccesarry. Remember we give bot.add_cog() the name of the class in this case SimpleCog. # When we load the cog, we use the name of the file. def setup(bot): bot.add_cog(SimpleCog(bot)) -
EvieePy revised this gist
Aug 26, 2017 . 1 changed file with 23 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -26,7 +26,29 @@ async def show_toprole(self, ctx, *, member: discord.Member=None): member = ctx.author await ctx.send(f'The top role for {member.display_name} is {member.top_role.name}') @commands.command(name='perms', aliases=['perms_for', 'permissions']) @commands.guild_only() async def check_permissions(self, ctx, *, member: discord.Member=None): """A simple command which checks a members Guild Permissions. If member is not provided, the author will be checked.""" if not member: member = ctx.author # Here we check if the value of each permission is True. perms = '\n'.join(perm for perm, value in member.guild_permissions if value) # And to make it look nice, we wrap it in an Embed. embed = discord.Embed(title='Permissions for:', description=ctx.guild.name, colour=member.colour) embed.set_author(icon_url=member.avatar_url, name=str(member)) # \uFEFF is a Zero-Width Space, which basically allows us to have an empty field name. embed.add_field(name='\uFEFF', value=perms) await ctx.send(content=None, embed=embed) # Thanks to Gio for the Command. def setup(bot): bot.add_cog(Members(bot)) -
EvieePy revised this gist
Aug 26, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -25,7 +25,7 @@ async def show_toprole(self, ctx, *, member: discord.Member=None): if member is None: member = ctx.author await ctx.send(f'The top role for {member.display_name} is {member.top_role.name}') def setup(bot): -
EvieePy revised this gist
Aug 26, 2017 . 2 changed files with 33 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -38,7 +38,7 @@ def get_prefix(bot, msg): return commands.when_mentioned_or(*prefixes)(bot, msg) initial_extensions = ('cogs.simple', 'cogs.members',) bot = commands.Bot(command_prefix=get_prefix, description='A Rewrite Cog Example') This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ import discord from discord.ext import commands class Members: def __init__(self, bot): self.bot = bot @commands.command() @commands.guild_only() async def joined(self, ctx, *, member: discord.Member): """Says when a member joined.""" await ctx.send(f'{member.display_name} joined on {member.joined_at}') @commands.command(name='bot') async def _bot(self, ctx): """Is the bot cool?""" await ctx.send('Yes, the bot is cool.') @commands.command(name='top_role', aliases=['toprole']) @commands.guild_only() async def show_toprole(self, ctx, *, member: discord.Member=None): """Simple command which shows the members Top Role.""" if member is None: member = ctx.author await ctx.send(f'The top role for {member.display_name} is {member.top_role}') def setup(bot): bot.add_cog(Members(bot)) -
EvieePy revised this gist
Aug 20, 2017 . 1 changed file with 14 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -49,8 +49,7 @@ async def only_me(self, ctx): async def example_embed(self, ctx): """A simple command which showcases the use of embeds. Have a play around and visit the Visualizer.""" embed = discord.Embed(title='Example Embed', description='Showcasing the use of Embeds...\nSee the visualizer for more info.', @@ -66,6 +65,19 @@ async def example_embed(self, ctx): await ctx.send(content='**A simple Embed for discord.py@rewrite in cogs.**', embed=embed) async def on_member_ban(self, guild, user): """Event Listener which is called when a user is banned from the guild. For this example I will keep things simple and just print some info. Notice how because we are in a cog class we do not need to use @bot.event For more information: http://discordpy.readthedocs.io/en/rewrite/api.html#discord.on_member_ban Check above for a list of events. """ print(f'{user.name}-{user.id} was banned from {guild.name}-{guild.id}') def setup(bot): bot.add_cog(SimpleCog(bot)) -
EvieePy revised this gist
Aug 20, 2017 . 1 changed file with 29 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ For a list of inbuilt checks: http://dischttp://discordpy.readthedocs.io/en/rewrite/ext/commands/api.html#checksordpy.readthedocs.io/en/rewrite/ext/commands/api.html#checks You could also create your own custom checks. Check out: https://github.com/Rapptz/discord.py/blob/master/discord/ext/commands/core.py#L689 @@ -21,13 +21,13 @@ class SimpleCog: def __init__(self, bot): self.bot = bot @commands.command(name='repeat', aliases=['copy', 'mimic']) async def do_repeat(self, ctx, *, our_input: str): """A simple command which repeats our input. In rewrite Context is automatically passed to our commands as the first argument after self.""" await ctx.send(our_input) @commands.command(name='add', aliases=['plus']) @commands.guild_only() @@ -36,13 +36,35 @@ async def do_addition(self, ctx, first: int, second: int): total = first + second await ctx.send(f'The sum of **{first}** and **{second}** is **{total}**') @commands.command(name='me') @commands.is_owner() async def only_me(self, ctx): """A simple command which only responds to the owner of the bot.""" await ctx.send(f'Hello {ctx.author.mention}. This command can only be used by you!!') @commands.command(name='embeds') @commands.guild_only() async def example_embed(self, ctx): """A simple command which showcases the use of embeds. Have a play around and visit the Visualizer: https://leovoel.github.io/embed-visualizer/""" embed = discord.Embed(title='Example Embed', description='Showcasing the use of Embeds...\nSee the visualizer for more info.', colour=0x98FB98) embed.set_author(name='MysterialPy', url='https://gist.github.com/MysterialPy/public', icon_url='http://i.imgur.com/ko5A30P.png') embed.set_image(url='https://cdn.discordapp.com/attachments/84319995256905728/252292324967710721/embed.png') embed.add_field(name='Embed Visualizer', value='[Click Here!](https://leovoel.github.io/embed-visualizer/)') embed.add_field(name='Command Invoker', value=ctx.author.mention) embed.set_footer(text='Made in Python with discord.py@rewrite', icon_url='http://i.imgur.com/5BFecvA.png') await ctx.send(content='**A simple Embed for discord.py@rewrite in cogs.**', embed=embed) def setup(bot): -
EvieePy revised this gist
Aug 20, 2017 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import sys, traceback """This is a multi file example showcasing many features of the command extension and the use of cogs. These are examples only and are not intended to be used as a fully functioning bot. Rather they should give you a basic understanding and platform for creating your own bot. -
EvieePy revised this gist
Aug 20, 2017 . 2 changed files with 9 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,9 +7,9 @@ These are examples only and are not intended to be used as a fully functioning bot. Rather they should give you a basic understanding and platform for creating your own bot. These examples make use of Python 3.6.2 and the rewrite version on the lib. For examples on cogs for the async version: https://gist.github.com/leovoel/46cd89ed6a8f41fd09c5 Rewrite Documentation: This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,13 +2,18 @@ from discord.ext import commands """A simple cog example with simple commands. Showcased here are some check decorators, and the use of events in cogs. For a list of inbuilt checks: http://dischttp://discordpy.readthedocs.io/en/rewrite/ext/commands/api.html#checksordpy.readthedocs.io/en/rewrite/ext/commands/api.html#checks You could also create your own custom checks. Check out: https://github.com/Rapptz/discord.py/blob/master/discord/ext/commands/core.py#L689 For a list of events: http://discordpy.readthedocs.io/en/rewrite/api.html#event-reference http://discordpy.readthedocs.io/en/rewrite/ext/commands/api.html#event-reference """ class SimpleCog: -
EvieePy revised this gist
Aug 20, 2017 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,7 +23,7 @@ def get_prefix(bot, msg): """A callable Prefix for our bot. This could be edited to allow per server prefixes.""" # Notice how you can use spaces in prefixes. Try to keep them simple though. prefixes = ['>?', 'lol ', '!?'] @@ -44,7 +44,7 @@ def get_prefix(bot, msg): @bot.event async def on_ready(): """http://discordpy.readthedocs.io/en/rewrite/api.html#discord.on_ready""" print(f'\n\nLogged in as: {bot.user.name} - {bot.user.id}\nVersion: {discord.__version__}\n') -
EvieePy revised this gist
Aug 20, 2017 . 2 changed files with 19 additions and 86 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -24,15 +24,7 @@ def get_prefix(bot, msg): """A callable Prefix for our bot. This could be edited to allow per server prefixes. # Notice how you can use spaces in prefixes. Try to keep them simple though. prefixes = ['>?', 'lol ', '!?'] @@ -44,29 +36,16 @@ def get_prefix(bot, msg): # If we are in a guild, we allow for the user to mention us or use any of the prefixes in our list. return commands.when_mentioned_or(*prefixes)(bot, msg) initial_extensions = ('cogs.simple', 'cogs.handler',) bot = commands.Bot(command_prefix=get_prefix, description='A Rewrite Cog Example') @bot.event async def on_ready(): """http://discordpy.readthedocs.io/en/rewrite/api.html#discord.on_ready print(f'\n\nLogged in as: {bot.user.name} - {bot.user.id}\nVersion: {discord.__version__}\n') # Changes our bots Playing Status. type=1(streaming) for a standard game you could remove type and url. @@ -82,12 +61,5 @@ async def on_ready(): traceback.print_exc() print(f'Successfully logged in and booted...!') bot.run('TOKEN', bot=True, reconnect=True) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,80 +2,41 @@ from discord.ext import commands """A simple cog example with simple commands. For a list of inbuilt checks: http://dischttp://discordpy.readthedocs.io/en/rewrite/ext/commands/api.html#checksordpy.readthedocs.io/en/rewrite/ext/commands/api.html#checks You could also create your own custom checks. Check out: https://github.com/Rapptz/discord.py/blob/master/discord/ext/commands/core.py#L689""" class SimpleCog: """SimpleCog""" def __init__(self, bot): self.bot = bot @commands.command(name='repeat', aliases=['copy', 'mimic']) async def do_repeat(self, ctx, *, our_input: str): """A simple command which repeats our input. In rewrite Context is automatically passed to our commands as the first argument after self.""" await ctx.send(f'{our_input}') @commands.command(name='add', aliases=['plus']) @commands.guild_only() async def do_addition(self, ctx, first: int, second: int): """A simple command which does addition on two integer values.""" total = first + second await ctx.send(f'The sum of **{first}** and **{second}** is **{total}**') @commands.command(name='me') @commands.is_owner() async def only_me(self, ctx): """A simple command which only responds to the owner of the bot.""" await ctx.send(f'Hello {ctx.author.mention}. I only respond to you!') -
EvieePy revised this gist
Aug 20, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -76,7 +76,7 @@ async def only_me(self, ctx): http://discordpy.readthedocs.io/en/rewrite/api.html#discord.Member.mention""" await ctx.send(f'Hello {ctx.author.mention}. I only respond to you!') def setup(bot): -
EvieePy revised this gist
Aug 20, 2017 . 2 changed files with 84 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -50,8 +50,7 @@ def get_prefix(bot, msg): Format: folder.file""" initial_extensions = ('cogs.simple', 'cogs.handler',) """Here we instance our bot... commands.Bot subclasses discord.Client, thus it can do everything Client can and more. This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,83 @@ import discord from discord.ext import commands """A simple cog example with simple commands.""" class SimpleCog: """SimpleCog""" def __init__(self, bot): self.bot = bot '''Below we create our command {repeat}. Our command function must be a |coroutine| The command decorator takes in several Optional[arguments]. name : Optional[str] - Used to call the command aliases : Optional[list[str]] - Used to call the command from a list of names. The command can also be called using the defined function name |do_repeat|. Notice the first parameter of our command function after self. ctx : Context In rewrite Context is automatically passed to our commands as the first argument after self. ''' @commands.command(name='repeat', aliases=['copy', 'mimic']) async def do_repeat(self, ctx, *, inp: str): """A simple command which repeats our input. inp : [str]""" '''Here we see that |send| automatically retrieves the channel contained in context for us. This is similar to bot.say - (From async). It will send the message to the channel which the command was invoked.''' await ctx.send(f'{inp}') '''Below we create our command {add}. Our command function must be a |coroutine|. For this command we have added a check |guild_only|. This makes sure that our command can only be used in a guild. If it is used outside of a guild, the check will fail and an error will be sent to |on_command_error|. For a list of inbuilt checks: http://dischttp://discordpy.readthedocs.io/en/rewrite/ext/commands/api.html#checksordpy.readthedocs.io/en/rewrite/ext/commands/api.html#checks You could also create your own custom checks. Check out: https://github.com/Rapptz/discord.py/blob/master/discord/ext/commands/core.py#L689 ''' @commands.command(name='add', aliases=['plus']) @commands.guild_only() async def do_addition(self, ctx, first: int, second: int): """A simple command which does addition on two integer values. first : [int] second : [int]""" total = first + second await ctx.send(f'The sum of **{first}** and **{second}** is **{total}**') '''Below we create our command {me}. Our command function must be a |coroutine|. For this command we have added a check |is_owner|. This makes sure that our command can only be used by the bot owner. ''' @commands.command(name='me') @commands.is_owner() async def only_me(self, ctx): """A simple command which only responds to the owner of the bot. Showcased here is [Member.mention] which allows us to mention a member with ease. In this case the person who invoked the command, otherwise known as [author]. http://discordpy.readthedocs.io/en/rewrite/api.html#discord.Member.mention""" await ctx.send('Hello {ctx.author.mention}. I only respond to you!') def setup(bot): bot.add_cog(SimpleCog(bot)) -
EvieePy created this gist
Aug 19, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,94 @@ import discord from discord.ext import commands import sys, traceback """This is a multi file example showcasing many features of the command extension and the use of cogs. These are examples only and are not intended to be used as a fully functioning bot. Rather they should give you a basic understanding and platform for creating your own bot. These examples make use of |Python 3.6.2| and the |rewrite| version on the lib. For examples on cogs for the |async| version: https://gist.github.com/leovoel/46cd89ed6a8f41fd09c5 Rewrite Documentation: http://discordpy.readthedocs.io/en/rewrite/api.html Rewrite Commands Documentation: http://discordpy.readthedocs.io/en/rewrite/ext/commands/api.html Familiarising yourself with the documentation will greatly help you in creating your bot and using cogs. """ def get_prefix(bot, msg): """A callable Prefix for our bot. This could be edited to allow per server prefixes. For this example though we will keep it simple. We will allow for a [list] of prefixes or [mention] to serve as our prefix. We don't technically need a custom callable for this use case, but it showcases it's potential. Could be a |coroutine| bot : Bot msg : Message""" # Notice how you can use spaces in prefixes. Try to keep them simple though. prefixes = ['>?', 'lol ', '!?'] # Check to see if we are outside of a guild. e.g DM's etc. if msg.guild.id is None: # Only allow ? to be used in DMs return '?' # If we are in a guild, we allow for the user to mention us or use any of the prefixes in our list. return commands.when_mentioned_or(*prefixes)(bot, msg) """Here we define the cogs we would like to load when the bot starts. They will be loaded in |on_ready| below. It's a good idea to keep your cogs in a folder within your main package folder. In this case [cogs]. Notice how we use a dot path style, just as we do with imports. Format: folder.file""" initial_extensions = ('cogs.simple', 'cogs.owner', 'cogs.handler') """Here we instance our bot... commands.Bot subclasses discord.Client, thus it can do everything Client can and more. http://discordpy.readthedocs.io/en/rewrite/ext/commands/api.html#discord.ext.commands.Bot""" bot = commands.Bot(command_prefix=get_prefix, description='A Rewrite Cog Example') @bot.event async def on_ready(): """http://discordpy.readthedocs.io/en/rewrite/api.html#discord.on_ready When our bot has logged in and done preparing data, |on_ready| will be called. Here is a good place to do anything you need to when the bot initially loads. |coroutine|""" print(f'\n\nLogged in as: {bot.user.name} - {bot.user.id}\nVersion: {discord.__version__}\n') # Changes our bots Playing Status. type=1(streaming) for a standard game you could remove type and url. await bot.change_presence(game=discord.Game(name='Cogs Example', type=1, url='https://twitch.tv/kraken')) # Here we load our extensions listed above in [initial_extensions]. if __name__ == '__main__': for extension in initial_extensions: try: bot.load_extension(extension) except Exception as e: print(f'Failed to load extension {extension}.', file=sys.stderr) traceback.print_exc() print(f'Successfully logged in and booted...!') '''Here we start the event loop and attempt to login. Any code below this will not run until the bot has logged out and the event loop has been closed. For more information: http://discordpy.readthedocs.io/en/rewrite/ext/commands/api.html#discord.ext.commands.Bot.run If reconnect is True. The bot will attempt to reconnect before closing the loop in the case of disconnections/dropouts etc.''' bot.run('TOKEN', bot=True, reconnect=True)