GithubHelp home page GithubHelp logo

column01 / discord-moderation-bot Goto Github PK

View Code? Open in Web Editor NEW
103.0 9.0 60.0 89 KB

Modular Moderation bot for Discord

Python 100.00%
discord-py discord discord-bot python oops-in-python moderation-bot oop-in-python modular classloading classloader

discord-moderation-bot's Introduction

Hello, My name is Colin.

I'm a software developer who specializes in Python development. Below you will see a few pinned repositories, these are my favourite projects I've worked on and are good examples of the code I am capable of writing.

Projects I am working on/maintain

  • mark2 (maintainer) - Minecraft server wrapper written in Python 3 using Twisted

Favourite Project

My favourite project is my discord moderation bot that uses class loading to allow a user to make the bot their own. Simply adding scripts to a folder with some command or event handler classes allows the user to add to the bot without even restarting the program!

The event handlers are added to the main script using Python "reflection" and some clever techniques that enable my code to be an order of magnitude smaller compared to implementing each event function. It takes some info provided by the handler class and creates a function in the bot using a template renamed on_<event>. Effectively ~40 lines of code can handle what could have been upwards of thousands of lines and is completely future-proof. When new events are added, I don't even need to write any new code to handle their addition.

discord-moderation-bot's People

Contributors

column01 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

discord-moderation-bot's Issues

Error in console:

When I try running it, I receive this error:

  File "main.py", line 6, in <module>
    from tasks.check_punishments import check_punishments
ModuleNotFoundError: No module named 'tasks.check_punishments'

AttributeError: module 'asyncio' has no attribute 'coroutine'. Did you mean: 'coroutines'?

I get this error:
Initializing the command registry handler. This does not start registering commands!
Registering commands...
The bot has been initialized with the following commands: ban, unban, mod, mute, tempmute, unmute, reload, rl
Initializing the event registry handler. This does not start registering events!
Registering events...
Traceback (most recent call last):
File "C:\Users\XXXX\Bot\bot.py", line 155, in
bot = ModerationBot(intents)
^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\XXXX\Bot\bot.py", line 32, in init
self.event_registry.register_events()
File "C:\Users\XXXX\Bot\event_registry.py", line 89, in register_events
setattr(self.instance, event_name, asyncio.coroutine(functools.partial(self.instance.event_template, event_name=event_name)))
^^^^^^^^^^^^^^^^^
AttributeError: module 'asyncio' has no attribute 'coroutine'. Did you mean: 'coroutines'?

Mod role isn't recognized as Moderator

Hello,
I have tested the bot, and noticed that once i added a role id to the mod_roles, the user ( not admin ) who has that role receives a " You must be a moderator to use this command. ".

Error in console. How to fix?

\Discord-Moderation-Bot-master\Discord-Moderation-Bot-master\bot.py", line 155, in
bot.run(token)
File "C:\Users\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\client.py", line 723, in run
return future.result()
File "C:\Users\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\client.py", line 702, in runner
await self.start(*args, **kwargs)
File "C:\Users\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\client.py", line 665, in start
await self.login(*args, bot=bot)
File "C:\Users\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\client.py", line 511, in login
await self.http.static_login(token.strip(), bot=bot)
File "C:\Users\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\http.py", line 304, in static_login
raise LoginFailure('Improper token has been passed.') from exc
discord.errors.LoginFailure: Improper token has been passed.
Exception ignored in: <function _ProactorBasePipeTransport.del at 0x0000022EA815E700>
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3568.0_x64__qbz5n2kfra8p0\lib\asyncio\proactor_events.py", line 116, in del
self.close()
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3568.0_x64__qbz5n2kfra8p0\lib\asyncio\proactor_events.py", line 108, in close
self._loop.call_soon(self._call_connection_lost, None)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3568.0_x64__qbz5n2kfra8p0\lib\asyncio\base_events.py", line 751, in call_soon
self._check_closed()
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3568.0_x64__qbz5n2kfra8p0\lib\asyncio\base_events.py", line 515, in _check_closed
raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed

cannot import helpers.embed_builder

Discussed in #21

Originally posted by davidavidavi123 December 28, 2021
um i just downloaded the bot, and trying to run it, but i get the error:
Initializing the command registry handler. This does not start registering commands!
Registering commands...
Traceback (most recent call last):
File "C:\Users\23740\Downloads\Discord-Moderation-Bot-master\Discord-Moderation-Bot-master\bot.py", line 154, in
bot = ModerationBot()
self.registry.register_commands()
File "C:\Users\23740\Downloads\Discord-Moderation-Bot-master\Discord-Moderation-Bot-master\command_registry.py", line 75, in register_commands
command_module = importlib.import_module("commands.{}".format(fname))
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2544.0_x64__qbz5n2kfra8p0\lib\importlib_init_.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1030, in _gcd_import
File "", line 1007, in _find_and_load
File "", line 986, in _find_and_load_unlocked
File "", line 680, in _load_unlocked
File "", line 850, in exec_module
File "", line 228, in call_with_frames_removed
File "C:\Users\23740\Downloads\Discord-Moderation-Bot-master\Discord-Moderation-Bot-master\commands\ban.py", line 6, in
from helpers.embed_builder import EmbedBuilder
ModuleNotFoundError: No module named 'helpers.embed_builder'
PS C:\Users\23740\Downloads\Discord-Moderation-Bot-master\Discord-Moderation-Bot-master> python3 bot.py
Initializing the command registry handler. This does not start registering commands!
Registering commands...
Traceback (most recent call last):
File "C:\Users\23740\Downloads\Discord-Moderation-Bot-master\Discord-Moderation-Bot-master\bot.py", line 154, in
bot = ModerationBot()
File "C:\Users\23740\Downloads\Discord-Moderation-Bot-master\Discord-Moderation-Bot-master\bot.py", line 25, in init
self.registry.register_commands()
File "C:\Users\23740\Downloads\Discord-Moderation-Bot-master\Discord-Moderation-Bot-master\command_registry.py", line 75, in register_commands
command_module = importlib.import_module("commands.{}".format(fname))
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2544.0_x64__qbz5n2kfra8p0\lib\importlib_init
.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1030, in _gcd_import
File "", line 1007, in _find_and_load
File "", line 986, in _find_and_load_unlocked
File "", line 680, in _load_unlocked
File "", line 850, in exec_module
File "", line 228, in _call_with_frames_removed
File "C:\Users\23740\Downloads\Discord-Moderation-Bot-master\Discord-Moderation-Bot-master\commands\ban.py", line 6, in
from helpers.embed_builder import EmbedBuilder
ModuleNotFoundError: No module named 'helpers.embed_builder'
i think the helpers file is not importing correctly, pls help

Unban Command

Hi , while trying to unban a banned user i encoutered this error! Also , i think you should also add an help command would be really helpful!
Capture

Storage explanation

I'm not sure if this is active but if it is...

Can someone give a brief explanation of how the storage system works. I planned to have a storage system where different things are stored in different json files but this appears to all be in one and i'm not quite sure how this works/how to use it.

Thanks.

dumb but...

how do I run it and where do I put the token??

main.py Not found

it is showing main.py not found as the error and there is no main.py

Why not @ mentions instead of user id's.

Why not @ mentions instead of user id's.
It would be more convenient for moderators to use @ mentions while doing the commands.

Eg: !tempmute @ricardo#9898 5s

Error console

I have this error can you help me ?
File "E:\Claquetteria\Discord-Bot-Template\Claquetteria-Moderation\bot.py", line 154, in <module> bot = ModerationBot() File "E:\Claquetteria\Discord-Bot-Template\Claquetteria-Moderation\bot.py", line 48, in __init__ discord.Client.__init__(self) TypeError: Client.__init__() missing 1 required keyword-only argument: 'intents'

WTF is happening here

2021-05-09T06:59:47.600228+00:00 heroku[worker.1]: Starting process with command `python main.py`
2021-05-09T06:59:48.518755+00:00 heroku[worker.1]: State changed from starting to up
2021-05-09T06:59:51.874503+00:00 heroku[worker.1]: Process exited with status 1
2021-05-09T06:59:51.969495+00:00 heroku[worker.1]: State changed from up to crashed
2021-05-09T06:59:51.778506+00:00 app[worker.1]: Initializing the command registry handler. This does not start registering commands!
2021-05-09T06:59:51.778760+00:00 app[worker.1]: Traceback (most recent call last):
2021-05-09T06:59:51.778761+00:00 app[worker.1]:   File "/app/main.py", line 180, in <module>
2021-05-09T06:59:51.778945+00:00 app[worker.1]:     bot = ModerationBot()
2021-05-09T06:59:51.778949+00:00 app[worker.1]:   File "/app/main.py", line 23, in __init__
2021-05-09T06:59:51.779100+00:00 app[worker.1]:     from command_registry import registry
2021-05-09T06:59:51.779101+00:00 app[worker.1]:   File "/app/command_registry.py", line 94, in <module>
2021-05-09T06:59:51.779256+00:00 app[worker.1]:     registry = CommandRegistry()
2021-05-09T06:59:51.779257+00:00 app[worker.1]:   File "/app/command_registry.py", line 16, in __init__
2021-05-09T06:59:51.779456+00:00 app[worker.1]:     self.get_py_files(overwrite=True)
2021-05-09T06:59:51.779484+00:00 app[worker.1]:   File "/app/command_registry.py", line 46, in get_py_files
2021-05-09T06:59:51.779713+00:00 app[worker.1]:     from bot import __location__
2021-05-09T06:59:51.779816+00:00 app[worker.1]: ModuleNotFoundError: No module named 'bot'

help

Traceback (most recent call last):
File "C:\Users\lazyn\Desktop\Discord-Moderation-Bot-master\bot.py", line 153, in
intents.message_content = True
^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Intents' object has no attribute 'message_content'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.