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}"

import aiohttp
import asyncio

async def fetch_quote():
    async with aiohttp.ClientSession() as session:
        async with session.get("https://zenquotes.io/api/random") as response:
            if response.status == 200:
                json_response = await response.json()
                return json_response[0]["q"] + " -" + json_response[0]["a"]
            else:
                return "Failed to fetch quote."

def start_bot(token):

About this template

ZenQuoteBot: A Discord bot that sends a quote every 1 day to the server using the Zen quotes API.

Introduction to the ZenQuote Discord Bot Template

Welcome to the ZenQuote Discord Bot template! This template allows you to create a Discord bot that sends a daily inspirational quote to your server. The bot uses the Zen quotes API to fetch quotes and posts them in a text channel of your choice. This guide will walk you through the steps to set up and deploy your bot using the Lazy platform.

Getting Started

To begin using this template, 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: Adding Environment Secrets

Before you can test and deploy your bot, you'll need to set up a couple of environment secrets within the Lazy Builder:

  • CLIENT_ID: The unique identifier for your Discord application.
  • BOT_TOKEN: The token that allows your bot to log in to Discord.

To obtain these values, follow these steps:

  • Go to the Discord Developer Portal and create a new application.
  • In the 'Bot' section, click 'Add Bot' and confirm the action.
  • 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 and set the CLIENT_ID and BOT_TOKEN with the respective values you copied.

Test: Pressing the Test Button

Once you have set up the environment secrets, press the "Test" button on the Lazy platform. This will begin the deployment of your bot and launch the Lazy CLI. You will not be prompted for any additional user input at this stage.

Using the App

After pressing the "Test" button, Lazy will handle the deployment of your bot. Once the bot is deployed, it will start sending a quote every day to the text channels of the servers it has been added to. There is no frontend interface for this bot; its functionality is entirely within the Discord environment.

Integrating the App

To integrate the bot into your Discord server, you will need to use the OAuth link provided in the Lazy CLI after deployment. This link is used to invite the bot to your Discord server. Follow these steps:

  • Copy the OAuth link from the Lazy CLI output.
  • Paste the link into your web browser and select the server you want to add the bot to.
  • Authorize the bot with the necessary permissions to post messages in your server.

Once the bot is added to your server, it will begin its daily routine of sending inspirational quotes to a text channel.

That's it! You've successfully set up the ZenQuote Discord Bot using the Lazy platform. Enjoy your daily dose of inspiration!

Category
Technology
Last published
May 11, 2024

More templates like this

Versatile Input Form

Develop a versatile input form for users.

Streamlit
Python

AI Specific Website Scraper

Provide a url and the information you need to extract . It will provide you the extracted information from that url

Selenium
Python

Demo of Playwright Text Scraper Working on Lazy

Playwright Text Scraper: A CLI app that navigates to http://example.com, retrieves the webpage title, and prints the content of all visible text elements.

Selenium
Python
Home
/
ZenQuote Discord Bot