/nma-bot

The official Neuromatch Academy bot required to facilitate courses across all community servers.

Primary LanguagePython

NMA Discord Bot

Description

The NMA Discord Bot is designed to automate various administrative tasks and interactions within the Neuromatch Academy's Discord Server. Its primary features include server and channel setup, member role assignment, member verification, automated pod handling, and dynamic activity generation and handling.

Getting Started

To use this bot, you need to have Python installed in your system. Python 3.8 or higher is recommended. Please also note that you must have a discord token for your bot to run. Instructions for how to obtain a token as well as how to invite your bot into a test server are available here.

Installation

  1. Clone the repository: git clone https://github.com/NeuromatchAcademy/nma-bot
  2. Navigate to the directory: cd nma-bot
  3. Install the necessary packages: pip install -r requirements.txt

Environmental Variables

This bot uses environmental variables stored in a .env file. You need to create this file and store your bot token as follows:

DISCORD_TOKEN=<Your Bot Token>

Contest Instructions

If you're forking this repository to participate in the NMA bot contest, here's some guidance to help you navigate the code:

How to add a command.

In nma-bot.py, under the on_message function, you can see that we split incoming messages based on spaces and if the first string in the list is '--nma', we assume that what follows is a command. From there, all you have to do is add an elif msg_cmd[1] == 'yourcommand' add add your code underneath. A sample command might thus look like this:

elif msg_cmd[1] == 'samplecommand':
    await message.channel.send(f"Sample command response, {message.author}!")

How to add a button.

In nma-bot.py, under the on_ready function, you can see that we send a message with a special view in the activity-center channel. This view is imported from utils/administrator.py, and if you look at the BUTTON_MAPPING dictionary in that file, you might notice that the dictionary's keys correspond to options in the #activity-center dropdown and the dictionary's values correspond to the buttons and dropdowns the bot loads if the appropriate option is picked in the dropdown. These are defined in utils/buttons.py as such:

class SampleButton(discord.ui.Button):
    def __init__(self, par):
        super().__init__(label='Button Label', style=discord.ButtonStyle.green)

    async def callback(self, interaction: discord.Interaction):
        await interaction.response.send_message(f'Sample button response, {interaction.user}!', ephemeral=True)

From there, you'd add buttons.SampleButton into the appropriate list in the BUTTON_MAPPING dictionary in utils/administrator.py.

Key documentation

Disclaimer

This bot is designed to be used in Neuromatch Academy course servers and expects a certain server structure as a result. If you server is misconfigured, it will not work for you.

Licensing

CC BY 4.0

CC BY 4.0 BSD-3

The contents of this repository are shared under under a Creative Commons Attribution 4.0 International License.

Software elements are additionally licensed under the BSD (3-Clause) License.

Derivative works may use the license that is more appropriate to the relevant context.