import os
import discord
from discord.ext import commands

def generate_oauth_link(client_id):
    base_url = "https://discord.com/api/oauth2/authorize"
    redirect_uri = "http://localhost"
    scope = "bot"
    permissions = "8"  # Administrator permission for simplicity, adjust as needed.
    return f"{base_url}?client_id={client_id}&permissions={permissions}&scope={scope}"

def start_bot(token):
    intents = discord.Intents.default()
    intents.messages = True
    bot = commands.Bot(command_prefix='!', intents=intents)

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

    bot.run(token)

def main():
    client_id = os.environ.get('CLIENT_ID')

About this template

This powerful app skeleton is a great starting place for a Discord bot

Introduction to the Discord Bot Template

Welcome to the Discord Bot Template on Lazy! This template is designed to help you create a Discord bot with ease. The bot is capable of responding to commands and can be customized to suit your needs. Whether you're looking to automate tasks, moderate your server, or add fun interactions for your community, this template is a great starting point.

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, so you won't need to copy, paste, or delete any code manually.

Initial Setup: Adding Environment Secrets

Before you can test and deploy your Discord bot, you'll need to set up a couple of environment secrets within the Lazy Builder. These secrets are the CLIENT_ID and BOT_TOKEN, which are essential for your bot to interact with the Discord API.

  • Go to the Discord Developer Portal and create a new application.
  • Navigate to the 'Bot' section and click 'Add Bot'.
  • Under the 'TOKEN' section, click 'Copy' to get your BOT_TOKEN.
  • Navigate to the 'OAuth2' section, and under 'CLIENT ID', click 'Copy' to get your CLIENT_ID.
  • Back in the Lazy Builder, go to the Environment Secrets tab.
  • Add two new secrets: one named CLIENT_ID and the other named BOT_TOKEN, pasting the respective values you copied from the Discord Developer Portal.

Test: Deploying the Bot

With your environment secrets in place, you're ready to deploy your bot. Press the "Test" button on the Lazy platform. This will begin the deployment of your app and launch the Lazy CLI. You won't need to provide any additional user input at this stage, as the CLIENT_ID and BOT_TOKEN are already set as environment secrets.

Using the Bot

Once your bot is deployed, you can invite it to your Discord server using the OAuth link that will be printed in the Lazy CLI. The bot will start automatically and will be ready to respond to commands in your server. You can interact with your bot by typing commands prefixed with '!' (or any other prefix you set) in your Discord server's text channels.

Integrating the Bot

To fully integrate your bot into your Discord server, you may want to customize its commands and functionality. Here's a sample of how you might add a simple command to your bot:


@bot.command()
async def greet(ctx):
    await ctx.send("Hello, I'm your friendly Discord bot!")

Add this code snippet to your main.py file in the Lazy Builder interface to create a new command that makes your bot greet users when they type '!greet'.

Remember to adjust the bot's permissions and functionality according to your server's needs. You can do this by modifying the permissions parameter in the generate_oauth_link function or by adding more commands and event listeners to your bot's code.

Once you're happy with your bot, you can share the OAuth link with your server members or add it to your server's website to allow others to invite the bot to their servers as well.

That's it! You've successfully set up and deployed a Discord bot using the Lazy platform. Enjoy your new bot, and have fun engaging with your community!

Category
Technology
Last published
July 20, 2024

More templates like this

AlphaBot Financial Summary

AlphaBot Financial Summary: A Discord bot that utilizes the Alpha Vantage API to provide AI-generated summaries of income statements, balance sheets, and cash flow for renowned US companies.

Discord

Discord Moderation Bot

The Discord bot monitors all messages in the server. If a message contains profanity, the bot deletes it and sends a warning to the channel. The bot also notifies the host about the deletion via a direct message. Additionally, the bot outputs a helpful error message to a channel if there is a permissions error, guiding the server admin to enable the required permission in the Discord Developer portal.

Discord
Python
Flask

Discord Ticketbot Template

A simple Discord Ticketbot for your Discord Support Department. This Template and Bot is fully customizable but already build so that you can use it right away. You need a bot token from https://discord.com/developers/applications for your bot to work. These are the steps needed to get your token: "1. 🌐 Go to the Discord Developer Portal. 🌐\n" + "2. 🆕 Create a new application and navigate to the 'Bot' section. 🤖\n" + "3. 📋 Under the 'TOKEN' section, click 'Reset Token' to get your Discord bot token and confirm by clicking 'Yes, do it'. 🔑\n" + "4. 🤖 If your bot will have any ability to read/reply to messages, then under the 'BOT' section, enable the slider titled 'Message Content Intent' ✅" + "5. 🔐 Set the 'DISCORD_BOT_TOKEN' in the Env Secrets tab with your bot token from step 3. 🔐\n" + "For bot permissions, it's recommended to start with basic permissions and adjust as needed for your app's functionality.🚀") If you encounter any bugs, please tell Lazy to fix them and report them on the Official Lazy AI Discord to @D4vidG4merLP. Credits: @meow - the Discord bot slash command template @mrlazy.notlazy - supporting me And the Biggest Thank you. You for using this template ❤️

Discord
Home
/
Discord Bot