-
-
Notifications
You must be signed in to change notification settings - Fork 254
Set up some simple Discord bot boilerplate #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a30b4a5
Implemented flake8 and a Discord Bot base.
kovaceviccz 907186d
Missed cogs directory.
kovaceviccz 4828a96
Fix wrongful indentation.
kovaceviccz c0436c8
Add some comments and docstrings documenting the code and replacing m…
kovaceviccz a135873
Fix improper docstrings and comments.
kovaceviccz b0fa8b7
Use docstrings instead of block comments.
kovaceviccz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from pathlib import Path | ||
from sys import stderr | ||
from traceback import print_exc | ||
from os import environ | ||
|
||
from discord.ext import commands | ||
|
||
|
||
HACKTOBERBOT_TOKEN = environ.get('HACKTOBERBOT_TOKEN') | ||
bot = commands.Bot(command_prefix=commands.when_mentioned_or('!')) | ||
|
||
if __name__ == '__main__': | ||
# Scan for files in the /cogs/ directory and make a list of the file names. | ||
cogs = [file.stem for file in Path('cogs').glob('*.py')] | ||
for extension in cogs: | ||
try: | ||
bot.load_extension(f'cogs.{extension}') | ||
except Exception as e: | ||
print(f'Failed to load extension {extension}.', file=stderr) | ||
print_exc() | ||
|
||
bot.run(HACKTOBERBOT_TOKEN) |
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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from discord.ext import commands | ||
|
||
|
||
class Template: | ||
|
||
""" | ||
A template cog that contains examples of commands and command groups. | ||
""" | ||
|
||
def __init__(self, bot): | ||
self.bot = bot | ||
|
||
@commands.command(name='repo', aliases=['repository', 'project'], brief='A link to the repository of this bot.') | ||
async def repository(self, ctx): | ||
await ctx.send('https://github.com/discord-python/hacktoberbot') | ||
|
||
@commands.group(name='git', invoke_without_command=True) | ||
async def github(self, ctx): | ||
""" | ||
A command group with the name git. You can now create sub-commands such as git commit. | ||
""" | ||
|
||
await ctx.send('Resources to learn **Git**: https://try.github.io/.') | ||
|
||
@github.command() | ||
async def commit(self, ctx): | ||
""" | ||
A command that belongs to the git command group. Invoked using git commit. | ||
""" | ||
|
||
await ctx.send('`git commit -m "First commit"` commits tracked changes.') | ||
|
||
|
||
# Required in order to load the cog, use the class name in the add_cog function. | ||
def setup(bot): | ||
bot.add_cog(Template(bot)) |
Empty file.
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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
aiohttp==3.4.4 | ||
async-timeout==3.0.0 | ||
attrs==18.2.0 | ||
chardet==3.0.4 | ||
discord.py==1.0.0a0 | ||
idna==2.7 | ||
idna-ssl==1.1.0 | ||
multidict==4.4.2 | ||
websockets==6.0 | ||
yarl==1.2.6 |
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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[flake8] | ||
max-line-length=120 | ||
application_import_names=proj | ||
ignore=P102,B311,W503,E226,S311 | ||
exclude=__pycache__, venv, .venv, tests | ||
import-order-style=pycharm |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.