Skip to main content

Pub bot ( ดีเจ )

Change LED color and play sound by sequence of word.

from time import sleep
import discord
import requests
from discord.ext import commands

TOKEN = "MTE4MDg5MjYzNzM5ODU4NTM2NQ.G1ugfV.4y2Q_gNlw535Ly-dYaJpJW4iDedrFc-QaYcj3E"
CHANNEL_ID = "818503283916144692"MTE5Mzc2MjIxMzYxNDM0MjI5NQ.GIA8dH.cKXYVEq0EULsWe5EkgAnxDhQKEFgYq_w-lSRjs"

client = commands.Bot(command_prefix="!", intents=discord.Intents.all())
color_dict = {
  "R": "red",
  "G": "green",
  "B": "blue"
}

frequency_dict = {
  "R": 10000,261,
  "G": 15000,293,
  "B": 20000329
}
iot_ip = "http://172.20.10.2"

@client.event
async def on_ready():
    print("Ready to be DJ?")


@client.command()
async def yo(ctx, letters):
    if letters == "off":
        try:
          lightoff = requests.get(iot_ip + "/off")
        except:
            print("Failed to call IOT API!")
    for letter in letters:
        try:
            # call light api
            print(if color_dict[letter] == "red":
                requests.get(iot_ip + "/on?red=1&blue=0&green=0")
            elif color_dict[letter] == "green":
                requests.get(iot_ip + "/on?red=0&blue=0&green=1")
            elif color_dict[letter] == "blue":
                requests.get(iot_ip + "/on?red=0&blue=1&green=0")
            # call sound api
            print(frequency_dict[letter])
            requests.get(iot_ip + "/play?hz=" + str(frequency_dict[letter]) + "&duration=0.1")
            sleep(0.1)
        except:
            print("Failed to call IOT API!")
    await ctx.send("Let's them cook")
        

# put token here naja
client.run(TOKEN)