0

TL;DR:我正在尝试构建一个 Discord 机器人,以在按下物理按钮时发送脚本消息 - 返回错误代码以发送消息

我正在开发一个 Discord 机器人,以将实验室状态发送到我的俱乐部研讨会的特定频道。这应该是一个周末项目,但我们都知道这是怎么回事。我已经开始使用按钮等,但不确定如何使用 GPIO 引脚触发机器人命令。由于我不了解如何在计算机端而不是通过 !messages 触发消息,因此对我有意义的每个设置都会出现问题。

到目前为止,我的代码在这里:

from os import system
from datetime import date
from time import sleep

from gpiozero import LED, Button
import discord
from discord.ext import commands

with open('token.txt', 'r') as f:
    TOKEN = f.read()
with open('channel.txt', 'r') as f:
    CHANNEL = f.read()
description = '''EVC Lab Bot'''
bot = commands.Bot(command_prefix='!', description=description)

client = discord.Client()

openbutton=Button(17)
pendingbutton=Button(27)
closedbutton=Button(22)

openlight=LED(4)
pendinglight=LED(23)
closedlight=LED(24)

openmessage=':green_circle: :radio_button: :radio_button: OPEN :green_circle: :radio_button: :radio_button:'
pendingmessage=':radio_button: :yellow_circle: :radio_button: PENDING :radio_button: :yellow_circle: :radio_button:'
closedmessage=':radio_button: :radio_button: :red_circle: CLOSED :radio_button: :radio_button: :red_circle:'

@client.event
async def msg(status):
    await ctrx.send('shit works')


def on_ready():
    print('on ready')
    while True:
        if openbutton.is_pressed:
            print('sizable green button')
            msg('open')
            openlight.on()
            pendinglight.off()
            closedlight.off()
            openbutton.wait_for_release()
            sleep(10)
        elif pendingbutton.is_pressed:
            print('Large Yellow Button')
            
            openlight.off()
            pendinglight.on()
            closedlight.off()
            pendingbutton.wait_for_release()
            sleep(10)
        elif closedbutton.is_pressed:
            print('BIG RED BUTTON')
            
            openlight.off()
            pendinglight.off()
            closedlight.on()
            closedlight.wait_for_release()
            sleep(10)

bot.run(TOKEN)
print('booting')
on_ready()
4

0 回答 0