【发布时间】:2018-01-22 06:45:37
【问题描述】:
我正在用 python 制作一个不和谐的机器人,我一直试图让它 ping 一个网站,然后说它是启动还是关闭。 这是我的代码:
import logging
logging.basicConfig(level=logging.INFO)
import discord
from discord.ext import commands
import os
website = "mywebsite.com"
des = "a website status bot"
prefix = "."
client = commands.Bot(description=des, command_prefix=prefix)
async def my_background_task():
await client.wait_until_ready()
channel = discord.Object(id='my server id went here')
response = 0
while not client.is_closed:
print("loop") #debugger
await asyncio.sleep(10)
global response
pr = response
response = os.system("ping -c 1 " + website)
if response != 0:
response = 1
if pr != response:
if response == 0:
await client.send_message(channel, 'mywebsite is up!')
else:
await client.send_message(channel, 'mywebsite is down!')
client.run("discord-bot-code-went-here")
由于某种原因,它没有运行循环。有什么想法吗?
谢谢。
旁注:当我尝试使用它执行 ping pong 命令时,该机器人确实可以工作,因此它不是不和谐的连接,运行程序时也没有出现错误。
【问题讨论】:
标签: python python-3.x discord discord.py