File size: 1,691 Bytes
3b7c07e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4cb0b20
 
 
3b7c07e
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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"))