by yahya

Discord Logging Bot

Test this app for free
235
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

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

@bot.command()
@has_permissions(administrator=True)
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}')
Get full code

Discord Logging Bot

Created: | Last Updated:

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.

Here's a step-by-step guide for using the Discord Logging Bot template:

Introduction

The Discord Logging Bot is a utility bot designed to perform logging tasks on Discord. This bot can set a specific channel as the log channel and send logs to that channel. It's controlled via commands, making it easy to manage logging activities within your Discord server.

Getting Started

  1. Click "Start with this Template" to begin using the Discord Logging Bot template in Lazy.

  2. Press the "Test" button to deploy the app and launch the Lazy CLI.

Setting Up Your Discord Bot

Before you can use the Discord Logging Bot, you need to create a Discord bot and obtain its token. Follow these steps:

  1. Go to the Discord Developer Portal (https://discord.com/developers/applications).
  2. Click on "New Application" and give your application a name.
  3. Navigate to the "Bot" tab and click "Add Bot".
  4. Under the "Token" section, click "Copy" to copy your bot token.
  5. In the Lazy Builder, go to the Environment Secrets tab.
  6. Add a new secret with the key DISCORD_BOT_TOKEN and paste your bot token as the value.

Inviting the Bot to Your Server

  1. In the Discord Developer Portal, go to the "OAuth2" tab.
  2. In the "Scopes" section, select "bot".
  3. In the "Bot Permissions" section, select the necessary permissions (at minimum: Send Messages, View Channels, and Manage Messages).
  4. Copy the generated OAuth2 URL and open it in a new browser tab.
  5. Select the server you want to add the bot to and click "Authorize".

Using the Bot

Once the bot is in your server and the app is deployed, you can use the following commands:

  1. Set the log channel: !set_log_channel #channel-name Replace #channel-name with the channel you want to use for logging.

  2. Send a log message: !log Your log message here

Note that only users with administrator permissions can use these commands.

Integrating the Bot

This Discord bot runs as a standalone application and doesn't require additional integration steps. Simply ensure it's invited to your server and has the necessary permissions to function properly.

By following these steps, you'll have a functional Discord Logging Bot that can help you manage logs within your Discord server.

Technologies

Discord Discord
Python Python