TagMeMonday / main.py
Aditya Sharma
pinger
4cb0b20
raw
history blame
1.69 kB
import os
import threading
from flask import Flask
from dotenv import load_dotenv
import discord
from discord.ext import commands
load_dotenv()
intents = discord.Intents().default()
intents.message_content = True
intents.members = True
intents.message_content = True
bot = commands.Bot(command_prefix="!", intents=intents)
app = Flask(__name__)
async def handle_message(message: discord.Message):
user = message.author
content = message.content
if not content.startswith("!"):
return
content = content.replace("!", "")
command = content.split(" ")
if len(command) < 3:
await message.channel.send("Incorrent format")
return
match command[0]:
case "repeat":
try:
string = command[1]
repeatTimes = int(command[2])
for _ in range(repeatTimes):
await message.channel.send(string)
except Exception:
await message.channel.send("Error occurred!")
@bot.event
async def on_message(message):
# Ignore messages from the bot itself
if message.author == bot.user:
return
await handle_message(message) # Call your function
await bot.process_commands(message)
@bot.command()
async def server_id(ctx):
await ctx.send(f"The server ID is: {ctx.guild.id}")
@app.get("/")
def get_ping():
return "I am good"
def start_flask():
app.run(port=7860, host="0.0.0.0", debug=False)
@bot.event
async def on_ready():
print(f"Bot logged in as {bot.user}")
flask_thread = threading.Thread(target=start_flask)
flask_thread.start()
bot.run(os.getenv("DISCORD_BOT_TOKEN"))