Giter Site home page Giter Site logo

column01 / discord-moderation-bot Goto Github PK

View Code? Open in Web Editor NEW
111.0 9.0 59.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

Modular Discord Moderation Bot

A modular bot for moderating users on discord! Add custom commands and event handlers to customize the bot to your liking. Reload the bot using the builtin !reload or !reload events command to see your changes applied LIVE!

A Note Regarding Message Intents

This bot will only work for bots that are smaller as it requires the use of message intents, which for larger bots, requires verification from discord. This means if your bot will be in more than 100 severs you will not be able to use this method of doing commands and will need to code your own command handlers using the new interactions.

See this FAQ from discord regarding these changes.

There is a vague plan to update to use the new interaction based commands which offers a nicer user experience, but for now it will remain message based until I really get bored and need something to do

Quick Links

Adding your own commands

Adding your own event handlers

Adding your own persistent storage

Installation/Setup

Installing Requirements

  • Python Version >=3.8
  • discord.py Tested on 2.3.2
    • Windows install: python -m pip install discord.py
    • Linux install: pip3 install discord.py

Creating a bot account with Discord

  1. Go to the discord developer portal and create a new application
  2. Navigate to the Bot section and click Add a bot. Fill in the necessary info (like name and an image if you like)
  3. Scroll down to the Privileged Gateway Intents section and make sure to select the SERVER MEMBERS INTENT and MESSAGE CONTENT INTENT. Click save so it saves your changes!
  4. Now scroll back up and click the Reset Token button, follow the screen prompts until you can copy that token. This is how the program will log in as this bot account. DO NOT SHARE THIS TOKEN WITH ANYONE!
  5. Paste the newly copied token into a text file called token.txt in the same folder as the bot.py file.

Inviting the bot to your server

  1. On the application page for your bot in the discord developer portal, click the OAuth2 section.
  2. Now click the URL Generator section on the sidebar
  3. Select the bot scope and then select the Administrator permission in the newly displayed Bot Permissions checkbox list
  4. Copy the URL from the bottom and paste it into your browser. Follow the onscreen prompts to invite the bot to your server. You must be an administrator to invite the bot to the server.

Running the bot

  1. Open a command prompt in the root directory of the bot files (where bot.py is) and run the command python bot.py to run the bot.
  2. You should see some output on the screen talking about loading commands and logging in as the bot. If that all works, now you can use the bot!
  3. Add any moderator roles you want to the bot using the commands below!

Bot Information

  • Default prefix: !
  • <argument> = Required argument
  • [argument] = Optional argument
  • Durations can either be a formatted time that looks like the following: (1w2d3h4m5s) or time in seconds.
  • Durations can also use single types like 2m or 1w for example
  • All commands require you to be in a moderator role. See the commands below on how to add or remove a mod role (requires admin permission to add mod roles)
  • Read how to get the User ID here

Commands

  • !mod <add|remove|list> <role ID>

    • Adds, removes the role ID to the list of moderator roles.
    • If you want to list the roles, you do not need the role ID at the end.
  • !mute <user ID> [reason]

    • Permanently mutes the user. Must be unmuted manually.
  • !tempmute <user ID> <duration> [reason]

    • Temporarily mutes the user.
  • !unmute <user ID>

    • Unmutes the user
  • !ban <user ID> <duration> <reason>

    • Bans the user from the server for the duration specified
    • Reason is required. If you do not have a reason, you should not be banning them.
  • !unban <user ID>

    • Unbans the user from the server.
  • !reload

    • Reloads the command registry for any changes that were made to commands
  • !reload events

    • Reloads the event registry for any changes that were made

How to get user ID

You should follow the discord guide here

But the gist is:

  • Enable developer mode in discord
  • Right click their username in chat or on the sidebar
  • Click Copy ID

Issues with custom commands?

Ensure that:

  • Your command is a subclass of the base command class. (use from commands.base import Command and then define the class like this: class MyCommand(Command): so it is a subclass of it)
  • It has an async def execute(self, message, **kwargs): function to execute the command
  • It doesn't have basic python syntax errors.

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

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'

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'

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

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

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.

main.py Not found

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

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'

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. ".

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

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

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'

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'?

dumb but...

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

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.