by Lazy Sloth
Discord Member Engagement Bot
import discord
from discord.ext import commands
import asyncio
import os
from slack_sdk import WebClient
from slack_sdk.errors import SlackApiError
import pandas as pd
intents = discord.Intents.all()
intents.members = True
bot = commands.Bot(command_prefix="!", intents=intents)
# Slack client
slack_client = WebClient(token=os.environ["SLACK_API_TOKEN"])
# Metrics
engaged_users = set()
new_members = 0
members_left = 0
@bot.event
async def on_message(message):
global engaged_users
Discord Member Engagement Bot
Created: | Last Updated:
Introduction to the Discord Member Engagement Bot Template
Welcome to the Discord Member Engagement Bot Template! This bot is designed to help you track and measure user engagement within your Discord server. It counts unique engaged users, new members, and members who have left, and sends these metrics to a designated Slack channel every week. This article will guide you through the process of setting up and using this template on the Lazy platform.
Clicking Start with this Template
To begin using the Discord Member Engagement Bot Template, click on the "Start with this Template" button. This will initialize the template within the Lazy Builder interface, pre-populating the code necessary for the bot's functionality.
Initial Setup
Before you can use the bot, you'll need to set up a few environment secrets that the bot requires to function properly. These are the DISCORD_TOKEN, SLACK_API_TOKEN, and SLACK_CHANNEL. Here's how to acquire these values:
- DISCORD_TOKEN: This is the token for your Discord bot. You can obtain it by creating a bot application in the Discord Developer Portal and copying the token provided.
- SLACK_API_TOKEN: This token allows your bot to communicate with Slack. You can get it by creating a Slack app and installing it to your workspace, then navigating to the 'OAuth \& Permissions' page to find your 'Bot User OAuth Token'.
- SLACK_CHANNEL: This is the ID of the Slack channel where the bot will send messages. You can find this by navigating to your Slack workspace, selecting the desired channel, and looking at the URL. The channel ID is the last segment of the URL, typically starting with a 'C'.
Once you have these values, enter them into the Environment Secrets tab within the Lazy Builder.
Test: Pressing the Test Button
After setting up the environment secrets, press the "Test" button to deploy the app. The Lazy CLI will handle the deployment, and you won't need to install any libraries or set up your environment.
Entering Input
Analyze the code to see if the bot requires user input through the CLI. In this case, the bot does not require any additional user input, so you can skip this step.
Using the App
There is no frontend experience for this app, as its primary function is to operate in the background of your Discord server and send messages to Slack. Therefore, there is no interface to interact with directly within the app.
Integrating the App
After testing and confirming that the bot is running correctly, you'll need to invite the bot to your Discord server using the OAuth2 URL generated in the Discord Developer Portal. Ensure that you grant the bot the necessary permissions to read messages and track member events.
For Slack integration, make sure that your Slack app has the necessary permissions to post messages to the channel you've specified. You can adjust these permissions in the Slack app settings under 'OAuth \& Permissions'.
Once the bot is added to your Discord server and configured in Slack, it will begin tracking engagement metrics and sending weekly updates to your Slack channel automatically.
If you encounter any issues or need further assistance, refer to the documentation provided by Discord and Slack for creating bots and apps, respectively.
Discord Bot Documentation: https://discord.com/developers/docs/intro
Slack API Documentation: https://api.slack.com/
By following these steps, you should now have a fully functional Discord Member Engagement Bot running on the Lazy platform, providing valuable insights into your server's engagement directly to Slack.
Technologies
![Discord](https://media.pocketgamer.biz/2021/5/110514/discord-new-logo-2021-r225x225.jpg)
![Python](https://i.pinimg.com/originals/2f/9c/11/2f9c11f9e55efbf1791f12c06d60729b.jpg)
![Slack](https://a.slack-edge.com/80588/marketing/img/meta/slack_hash_256.png)