Discord Custom Commands Bot

Test this app for free
204
import discord
from discord.ext import commands
from discord.ext.commands import has_permissions
import random

intents = discord.Intents.default()  
intents.members = True

bot = commands.Bot(command_prefix='!', intents=intents)

# Global variables to store channel IDs
welcome_channel_id = None
leave_channel_id = None

@bot.event
async def on_ready():
    print(f'Logged in as {bot.user.name}')

@bot.event
async def on_member_join(member):
    role = discord.utils.get(member.guild.roles, name="New Member")
    if role:
        await member.add_roles(role)
    if welcome_channel_id:
Get full code

Discord Custom Commands Bot

Created: | Last Updated:

This bot will be designed to perform a variety of custom commands on Discord, including sending multiple messages and channels, using any role, auto-assigning roles on join, supporting custom emotes, displaying join & leave messages, making suggestions, auto color roles, and logging.

Introduction to the Discord Custom Commands Bot Template

Welcome to the Discord Custom Commands Bot template! This template is designed to help you create a Discord bot that can handle a variety of tasks such as sending welcome and leave messages, assigning roles, accepting suggestions, logging messages, and more. With this template, you can enhance your Discord server's functionality without needing to write the code from scratch.

Getting Started with the Template

To begin using this template, simply click on "Start with this Template" on the Lazy platform. This will pre-populate the code in the Lazy Builder interface, allowing you to customize the bot to your server's needs.

Initial Setup

Before you can use the bot, you need to set up a Discord bot token. This token will allow your bot to interact with the Discord API.

  1. Go to the Discord Developer Portal (https://discord.com/developers/applications).
  2. Create a new application and give it a name.
  3. Under the "Bot" tab, click "Add Bot" and confirm the creation.
  4. Copy the token provided under the "TOKEN" section.

Once you have your token, you will need to add it as an environment secret in the Lazy Builder:

  1. Go to the Environment Secrets tab within the Lazy Builder.
  2. Create a new secret with the key as 'DISCORD_BOT_TOKEN' and paste your Discord bot token as the value.

With the token set, your bot is ready to be deployed.

Test: Pressing the Test Button

After setting up your environment secret, press the "Test" button in the Lazy Builder. This will deploy your bot and launch the Lazy CLI. If the code requires any user input, you will be prompted to provide it through the CLI.

Entering Input

If the bot requires any additional input, such as setting the welcome or leave channel, you can use the commands provided in the bot's code. For example, to set the welcome channel, you would use the command !set_welcome_channel #channel-name in your Discord server, where "#channel-name" is the name of the channel you want to use for welcome messages.

Using the Bot

Once the bot is deployed and running, it will listen for commands and events on your Discord server. You can interact with the bot using the commands defined in the code, such as !suggest to make a suggestion, or !auto_color to assign a random color role to a user.

Integrating the Bot

To fully integrate the bot into your Discord server, you will need to invite it:

  1. Go back to the Discord Developer Portal and navigate to your application.
  2. Under the "OAuth2" tab, select "URL Generator" from the sidebar.
  3. In the "SCOPES" section, select "bot".
  4. In the "BOT PERMISSIONS" section, select the permissions your bot will need based on the commands it will execute.
  5. Copy the generated URL and open it in your web browser to invite the bot to your server.

After the bot joins your server, it will start responding to the events and commands as per the code in the template.

Remember, you can always go back to the Lazy Builder to make adjustments to your bot and redeploy it using the "Test" button. Enjoy automating your Discord server with your new custom commands bot!

Technologies

Discord Discord
Python Python