diff --git a/LICENSE.md b/LICENSE.md index cb62cfd0..3f8e977e 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2020 Krypton + Copyright 2021 Krypton Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/README.md b/README.md index 189ae6b0..0df844cd 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ python bot.py If you have any issues or questions of how to code a specific command, you can: -* Join my discord server [here](https://discord.gg/xkWRGBY) +* Join my discord server [here](https://discord.gg/HzJ3Gfr) * Post them [here](https://github.com/kkrypt0nn/Python-Discord-Bot-Template/issues) Me or other people will take their time to answer and help you. @@ -84,7 +84,7 @@ We use [SemVer](http://semver.org) for versioning. For the versions available, s ## Bots who used this template -*DM Krypton#2188 to get yourself in this list* +*DM Krypton#7331 to get yourself in this list* ## License diff --git a/UPDATES.md b/UPDATES.md index 3cf44e1b..021419bb 100644 --- a/UPDATES.md +++ b/UPDATES.md @@ -1,6 +1,11 @@ # Updates List Here is the list of all the updates that I made on this template. +### Version 2.1 +* Made the help command dynamic +* Added a small description to all commands +* Added intents when creating the bot + ### Version 2.0 * Added cogs * Added f-strings and removed `.format()` diff --git a/bot.py b/bot.py index c5c53fa1..d6b33ec9 100644 --- a/bot.py +++ b/bot.py @@ -3,7 +3,7 @@ Description: This is a template to create your own discord bot in python. -Version: 2.0 +Version: 2.1 """ import discord, asyncio, os, platform, sys @@ -19,12 +19,11 @@ For more information about intents, please go to the following websites: https://discordpy.readthedocs.io/en/latest/intents.html https://discordpy.readthedocs.io/en/latest/intents.html#privileged-intents -""" -intents = discord.Intents().default() + + +Default Intents: intents.messages = True intents.reactions = True -intents.presences = True -intents.members = True intents.guilds = True intents.emojis = True intents.bans = True @@ -39,7 +38,14 @@ intents.invites = True intents.voice_states = False intents.webhooks = False - + +Privileged Intents (Needs to be enabled on dev page): +intents.presences = True +intents.members = True +""" + +intents = discord.Intents.default() + bot = Bot(command_prefix=config.BOT_PREFIX, intents=intents) # The code in this even is executed when the bot is ready diff --git a/cogs/general.py b/cogs/general.py index c299bf9c..6f1d36af 100644 --- a/cogs/general.py +++ b/cogs/general.py @@ -11,6 +11,9 @@ def __init__(self, bot): @commands.command(name="info", aliases=["botinfo"]) async def info(self, context): + """ + Get some useful (or not) information about the bot. + """ embed = discord.Embed( description="Used Krypton's template", color=0x00FF00 @@ -40,6 +43,9 @@ async def info(self, context): @commands.command(name="serverinfo") async def serverinfo(self, context): + """ + Get some useful (or not) information about the server. + """ server = context.message.guild roles = [x.name for x in server.roles] role_length = len(roles) @@ -87,6 +93,9 @@ async def serverinfo(self, context): @commands.command(name="ping") async def ping(self, context): + """ + Check if the bot is alive. + """ embed = discord.Embed( color=0x00FF00 ) @@ -102,16 +111,25 @@ async def ping(self, context): @commands.command(name="invite") async def invite(self, context): + """ + Get the invite link of the bot to be able to invite it. + """ await context.send("I sent you a private message!") await context.author.send(f"Invite me by clicking here: https://discordapp.com/oauth2/authorize?&client_id={config.APPLICATION_ID}&scope=bot&permissions=8") @commands.command(name="server") async def server(self, context): + """ + Get the invite link of the discord server of the bot for some support. + """ await context.send("I sent you a private message!") - await context.author.send("Join my discord server by clicking here: https://discord.gg/Vddcy76") + await context.author.send("Join my discord server by clicking here: https://discord.gg/HzJ3Gfr") @commands.command(name="poll") async def poll(self, context, *args): + """ + Create a poll where members can vote. + """ poll_title = " ".join(args) embed = discord.Embed( title="A new poll has been created!", @@ -128,6 +146,9 @@ async def poll(self, context, *args): @commands.command(name="8ball") async def eight_ball(self, context, *args): + """ + Ask any question to the bot. + """ answers = ['It is certain.', 'It is decidedly so.', 'You may rely on it.', 'Without a doubt.', 'Yes - definitely.', 'As I see, yes.', 'Most likely.', 'Outlook good.', 'Yes.', 'Signs point to yes.', 'Reply hazy, try again.', 'Ask again later.', 'Better not tell you now.', @@ -145,6 +166,9 @@ async def eight_ball(self, context, *args): @commands.command(name="bitcoin") async def bitcoin(self, context): + """ + Get the current price of bitcoin. + """ url = "https://api.coindesk.com/v1/bpi/currentprice/BTC.json" # Async HTTP request async with aiohttp.ClientSession() as session: diff --git a/cogs/help.py b/cogs/help.py index 47d082f5..ba2d9c89 100644 --- a/cogs/help.py +++ b/cogs/help.py @@ -11,66 +11,20 @@ def __init__(self, bot): @commands.command(name="help") async def help(self, context): - # Note that commands made only for the owner of the bot are not listed here. - embed = discord.Embed( - title="Bot", - description="List of commands are:", - color=0x00FF00 - ) - embed.add_field( - name="Invite", - value=f"Usage: {config.BOT_PREFIX}invite", - inline=False - ) - embed.add_field( - name="Server", - value=f"Usage: {config.BOT_PREFIX}server", - inline=False - ) - embed.add_field( - name="Poll", - value=f"Usage: {config.BOT_PREFIX}poll ", - inline=False - ) - embed.add_field( - name="8ball", - value=f"Usage: {config.BOT_PREFIX}8ball ", - inline=False) - embed.add_field( - name="Bitcoin", - value=f"Usage: {config.BOT_PREFIX}bitcoin", - inline=False - ) - embed.add_field( - name="Info", - value=f"Usage: {config.BOT_PREFIX}info", - inline=False - ) - embed.add_field( - name="Kick", - value=f"Usage: {config.BOT_PREFIX}kick ", - inline=False - ) - embed.add_field( - name="Ban", - value=f"Usage: {config.BOT_PREFIX}ban ", - inline=False - ) - embed.add_field( - name="Warn", - value=f"Usage: {config.BOT_PREFIX}warn ", - inline=False - ) - embed.add_field( - name="Purge", - value=f"Usage: {config.BOT_PREFIX}purge ", - inline=False - ) - embed.add_field( - name="Help", - value=f"Usage: {config.BOT_PREFIX}help", - inline=False - ) + """ + List all commands from every Cog the bot has loaded. + """ + prefix = config.BOT_PREFIX + if not isinstance(prefix, str): + prefix = prefix[0] + embed = discord.Embed(title="Help", description="List of available commands:", color=0x00FF00) + for i in self.bot.cogs: + cog = self.bot.get_cog(i.lower()) + commands = cog.get_commands() + command_list = [command.name for command in commands] + command_description = [command.help for command in commands] + help_text = '\n'.join(f'{prefix}{n} - {h}' for n, h in zip(command_list, command_description)) + embed.add_field(name=i.capitalize(), value=f'```{help_text}```', inline=False) await context.send(embed=embed) def setup(bot): diff --git a/cogs/moderation.py b/cogs/moderation.py index ee92cad9..d0899ddb 100644 --- a/cogs/moderation.py +++ b/cogs/moderation.py @@ -11,6 +11,9 @@ def __init__(self, bot): @commands.command(name='kick', pass_context=True) async def kick(self, context, member: discord.Member, *args): + """ + Kick a user out of the server. + """ if context.message.author.guild_permissions.kick_members: if member.guild_permissions.administrator: embed = discord.Embed( @@ -55,6 +58,9 @@ async def kick(self, context, member: discord.Member, *args): @commands.command(name="nick") async def nick(self, context, member: discord.Member, *, name: str): + """ + Change the nickname of a user on a server. + """ if context.message.author.guild_permissions.administrator: try: if name.lower() == "!reset": @@ -83,6 +89,9 @@ async def nick(self, context, member: discord.Member, *, name: str): @commands.command(name="ban") async def ban(self, context, member: discord.Member, *args): + """ + Bans a user from the server. + """ if context.message.author.guild_permissions.administrator: try: if member.guild_permissions.administrator: @@ -123,6 +132,9 @@ async def ban(self, context, member: discord.Member, *args): @commands.command(name="warn") async def warn(self, context, member: discord.Member, *args): + """ + Warns a user in his private messages. + """ if context.message.author.guild_permissions.administrator: reason = " ".join(args) embed = discord.Embed( @@ -149,6 +161,9 @@ async def warn(self, context, member: discord.Member, *args): @commands.command(name="purge") async def purge(self, context, number): + """ + Delete a number of messages. + """ if context.message.author.guild_permissions.administrator: purged_messages = await context.message.channel.purge(limit=number) embed = discord.Embed( diff --git a/cogs/owner.py b/cogs/owner.py index 1ba79d0f..d7e9cd4a 100644 --- a/cogs/owner.py +++ b/cogs/owner.py @@ -11,6 +11,9 @@ def __init__(self, bot): @commands.command(name="shutdown") async def shutdown(self, context): + """ + Make the bot shutdown + """ if context.message.author.id in config.OWNERS: embed = discord.Embed( description="Shutting down. Bye! :wave:", @@ -29,6 +32,9 @@ async def shutdown(self, context): @commands.command(name="say", aliases=["echo"]) async def say(self, context, *, args): + """ + The bot will say anything you want. + """ if context.message.author.id in config.OWNERS: await context.send(args) else: @@ -41,6 +47,9 @@ async def say(self, context, *, args): @commands.command(name="embed") async def embed(self, context, *, args): + """ + The bot will say anything you want, but within embeds. + """ if context.message.author.id in config.OWNERS: embed = discord.Embed( description=args, @@ -57,6 +66,9 @@ async def embed(self, context, *, args): @commands.group(name="blacklist") async def blacklist(self, context): + """ + Lets you add or remove a user from not being able to use the bot. + """ if context.invoked_subcommand is None: embed = discord.Embed( title=f"There are currently {len(config.BLACKLIST)} blacklisted IDs", @@ -67,6 +79,9 @@ async def blacklist(self, context): @blacklist.command(name="add") async def blacklist_add(self, context, member: discord.Member): + """ + Lets you add a user from not being able to use the bot. + """ if context.message.author.id in config.OWNERS: userID = member.id try: @@ -97,6 +112,9 @@ async def blacklist_add(self, context, member: discord.Member): @blacklist.command(name="remove") async def blacklist_remove(self, context, member: discord.Member): + """ + Lets you remove a user from not being able to use the bot. + """ if context.message.author.id in config.OWNERS: userID = member.id try: diff --git a/config.py b/config.py index 0ec9add9..23820e08 100644 --- a/config.py +++ b/config.py @@ -7,4 +7,4 @@ # Default cogs that I have created for the template STARTUP_COGS = [ "cogs.general", "cogs.help", "cogs.moderation", "cogs.owner", -] +] \ No newline at end of file