Discord bot 不工作,也没有显示任何错误

时间:2020-12-26 12:05:34

标签: discord.py

我一直在尝试用 python 制作一个不和谐的机器人。我尝试了客户端 class Product(models.Model): ... class ProductImage(models.Model): product = models.ForeignKey(to=Product) value = models.ImageField() 事件并发现了 import time import serial import string import pynmea2 import lcd import geopy.distance import asyncio import threading ser = serial.Serial() ser.port = "/dev/ttyACM0" ser.baudrate = 9600 ser.timeout = 1 ser.open() ser.write(b'\xB5\x62\x06\x08\x06\x00\xFA\x00\x01\x00\x01\x00\x10\x96') #tell GPS module to report at 4 Hz reader = pynmea2.NMEAStreamReader(open(ser.port)) lcd.lcd_init() qual = 0 kmph = 0 alt = "?" sats = "0" timeStart = 1 timeDiff = 1 prevLat = 0 prevLon = 0 totalDist = 0 PDOP = 0 async def readGPS(): global qual global kmph global alt global sats global timeStart global timeDiff global prevLat global prevLon global totalDist global PDOP while True: try: for msg in reader.next(): if type(msg) == pynmea2.types.talker.GGA: timeDiff = time.time() - timeStart timeStart = time.time() #reset time to now qual = msg.gps_qual if msg.altitude == None: alt = "?" else: alt = round(msg.altitude) if str(msg.num_sats).startswith("0"): sats = str(msg.num_sats)[1] else: sats = str(msg.num_sats) if prevLat != 0 and kmph >= 2 and PDOP < 2.5: try: prevLatLon = (prevLat, prevLon) curLatLon = (float(msg.latitude), float(msg.longitude)) incr = geopy.distance.distance(prevLatLon, curLatLon).m totalDist += incr print(totalDist) except Exception as e: print(e) if int(msg.latitude) != 0: prevLat = float(msg.latitude) prevLon = float(msg.longitude) if type(msg) == pynmea2.types.talker.VTG: try: kmph = round(int(msg.spd_over_grnd_kmph)) except: kmph = 0 if type(msg) == pynmea2.types.talker.GSA: try: PDOP = float(msg.pdop) except: continue print(str(kmph) + ' ' + str(alt) + 'm ' + sats + ' sats, q' + str(qual) + ' Hz = ' + str(round(1/timeDiff, 1)), end='\r') except UnicodeDecodeError: continue except KeyboardInterrupt: lcd.lcd_byte(0x01, lcd.LCD_CMD) exit() async def updateLCD(): #Write info to LCD print("LCD") lcd.lcd_string(str(kmph) + ' ' + sats + ' sats', lcd.LCD_LINE_1) lcd.lcd_string(str(alt) + 'm q' + str(qual) + ' ' + str(round(1/timeDiff, 1)) + 'Hz', lcd.LCD_LINE_2) await asyncio.sleep(1) async def main(): while True: await readGPS() await updateLCD() loop = asyncio.get_event_loop() loop.create_task(main()) loop.run_forever() 。我写了非常简单的代码,抓了4个小时,仍然找不到问题所在。我所知道的是代码成功连接到客户端并且 vscode 没有显示任何问题。机器人不会回应任何事情

代码是:

on_message

1 个答案:

答案 0 :(得分:2)

装饰器后面需要括号,请改用 @bot.command()