import discord
import random
import pygame
import time
bot = discord.Client()
white_color = (255, 255, 255)
timer = pygame.time.Clock()
green_color = (0, 255, 0)
red_color = (255, 0, 0)
black_color = (0, 0, 0)
current_song = 0
@bot.event
async def on_message(msg):
if msg.author == bot.user:
return
if msg.content.startswith(''):
while True:
if current_song == 1:
await bot.send_message(msg.channel, ';;play https://www.youtube.com/watch?v=cUbFzEMQ2Fs')
elif current_song == 2:
await bot.send_message(msg.channel, ';;play https://www.youtube.com/watch?v=YlomIQF2zbI')
else:
await bot.send_message(msg.channel, "Hello!")
pygame.quit()
def create_window():
pygame.init()
display = pygame.display.set_mode((500, 500))
def draw_button(x, y, width, height, active_color, inactive_color, song_choice):
mouse_pos = pygame.mouse.get_pos()
mouse_click = pygame.mouse.get_pressed()
if x + width > mouse_pos[0] > x and y + height > mouse_pos[1] > y:
pygame.draw.rect(display, active_color, (x, y, width, height))
if mouse_click[0] == 1 and song_choice != 0:
pass # Do something when the button is pressed
else:
pygame.draw.rect(display, inactive_color, (x, y, width, height))
while True:
events = pygame.event.get()
display.fill(white_color)
draw_button(50, 50, 50, 50, red_color, green_color, 1)
draw_button(50, 120, 50, 50, red_color, green_color, 2)
pygame.display.update()
timer.tick(60)
@bot.event
async def on_ready():
print('Bot is online as')
print(bot.user.name)
print(bot.user.id)
print('------')
create_window()
bot.run('your_token_here')
I’m currently facing some difficulties and would appreciate any guidance on how to implement functionality so that the bot responds when I click a button on the Pygame interface. Thank you for any assistance!