Skip to content

Commit

Permalink
Template v2.1
Browse files Browse the repository at this point in the history
Added features:
- Small description to all commands
- Intents when creating the bot

Edited features:
- Made the help command dynamic
  • Loading branch information
kkrypt0nn committed Feb 10, 2021
1 parent 688926d commit d84df59
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 71 deletions.
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand Down
5 changes: 5 additions & 0 deletions UPDATES.md
Original file line number Diff line number Diff line change
@@ -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()`
Expand Down
18 changes: 12 additions & 6 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
26 changes: 25 additions & 1 deletion cogs/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
)
Expand All @@ -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!",
Expand All @@ -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.',
Expand All @@ -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:
Expand Down
74 changes: 14 additions & 60 deletions cogs/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Idea>",
inline=False
)
embed.add_field(
name="8ball",
value=f"Usage: {config.BOT_PREFIX}8ball <Question>",
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 <User> <Reason>",
inline=False
)
embed.add_field(
name="Ban",
value=f"Usage: {config.BOT_PREFIX}ban <User> <Reason>",
inline=False
)
embed.add_field(
name="Warn",
value=f"Usage: {config.BOT_PREFIX}warn <User> <Reason>",
inline=False
)
embed.add_field(
name="Purge",
value=f"Usage: {config.BOT_PREFIX}purge <Number>",
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):
Expand Down
15 changes: 15 additions & 0 deletions cogs/moderation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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":
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down
18 changes: 18 additions & 0 deletions cogs/owner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:",
Expand All @@ -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:
Expand All @@ -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,
Expand All @@ -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",
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
# Default cogs that I have created for the template
STARTUP_COGS = [
"cogs.general", "cogs.help", "cogs.moderation", "cogs.owner",
]
]

0 comments on commit d84df59

Please sign in to comment.