Discord Logging Bot

 import os
import discord
from discord.ext import commands
from discord.ext.commands import has_permissions

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

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

# Global variable to store channel ID
log_channel_id = None

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

async def set_log_channel(ctx, channel: discord.TextChannel):
    global log_channel_id
    log_channel_id = channel.id
    await ctx.send(f'Log channel set to {channel.mention}')

About this template

The Discord Logging Bot is a utility bot designed to perform logging tasks on Discord. This logger bot can set a specific channel as the log channel and send logs to that channel. The bot is controlled via commands. The '!set_log_channel #channel-name' command sets a specific channel as the log channel. The '!log message' command sends a log message to the set channel. The bot requires a Discord bot token (DISCORD_BOT_TOKEN) to function properly.

Introduction to the Discord Logging Bot Template

Welcome to the Discord Logging Bot template! This template is designed to help you create a bot that can log messages to a specific channel on your Discord server. It's perfect for server administrators who want to keep track of important events or messages. The bot can be easily controlled via commands, allowing you to set a log channel and send messages to it.

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 or paste any code manually.

Initial Setup

Before you can use the bot, you need to set up an environment secret for the Discord bot token. This token allows your bot to interact with the Discord API.

  1. Go to the Discord Developer Portal and create a new application.
  2. Under the "Bot" tab, click "Add Bot" and confirm the creation.
  3. Copy the bot token provided.
  4. Back in the Lazy Builder, navigate to the Environment Secrets tab.
  5. Create a new secret with the key DISCORD_BOT_TOKEN and paste the bot token you copied as the value.

Test: Pressing the Test Button

Once you have set up the environment secret, press the "Test" button in the Lazy platform. This will deploy your application and launch the Lazy CLI. The bot will start, and you should see a confirmation in the CLI that it has logged in successfully.

Entering Input

There is no need for user input through the CLI for this template, as all commands are given directly within Discord.

Using the App

After deploying the bot, you can interact with it on your Discord server. Make sure to invite the bot to your server using the OAuth2 URL generated in the Discord Developer Portal.

Integrating the App

To fully integrate the bot into your Discord server, follow these steps:

  1. Use the !set_log_channel #channel-name command in Discord to set the channel where you want the logs to be sent. Replace #channel-name with the actual channel you wish to use.
  2. Once the log channel is set, you can use the !log message command to send a log message to that channel. Replace message with the content you want to log.

Remember, you must have administrator permissions on the Discord server to use these commands.

That's it! Your Discord Logging Bot is now set up and ready to use. Enjoy your new logging capabilities on your Discord server.

If you need further assistance or have any questions, please refer to the discord.py documentation.

Last published
April 7, 2024

More templates like this

WhatsApp ChatBot (Twilio, InstantChat)

Build a WhatApp chatbot using Twilio, Discord and LazyAI.



GreetingBot: A discord bot that welcomes new members to your server.


Stock AI Advice

The bot requires certain permissions to function properly. These include the ability to read message history, send messages, and react to messages. The bot will generate stats such as This bot will provide ticker stats, commodity stats, Stock News and other AI Stock Trading Advice Please provide the Discord bot token in the Env Secrets tab under the name 'DISCORD_BOT_TOKEN' and your API Key for the Alpha Advantage

Discord Logging Bot