【发布时间】:2021-04-21 09:49:17
【问题描述】:
我正在开发一个机器人来检查特定的以太地址并检查令牌传输。一切都完成了 api 和东西,但我无法检查部分工作。它检查 addrs 并输出是否更改,但如何每 30 秒运行一次,并且输出不和谐。
我的代码:
import requests, time, json, sys, discord
result = requests.get('myapi')
result.json()
results = "soon:tm:"
def price_of_gas(inp):
def recursive_function(inp):
if type(inp) is list:
for i in inp:
ans = recursive_function(i)
if ans != None:
return ans
elif type(inp) is dict:
if 'name' in inp:
return inp['name']
for i in inp:
ans = recursive_function(inp[i])
if ans != None:
return ans
else:
return None
ans = recursive_function(inp)
return ans if ans else "Could NOT find the new token tx"
message.channel.send(price_of_gas(result.json()['operations'][0]['tokenInfo']['name']))
class MyClient(discord.Client):
async def on_ready(self):
print('Logged on as', self.user)
async def on_message(self, message):
# don't respond to ourselves
if message.author == self.user:
return
if message.content == '.get':
#send message
#checking other commands like '.help'
while True:
# Code executed here
print ('done')
time.sleep(1)
client = MyClient()
client.run("mytoken")
当脚本检查时看起来像这样,如果输出令牌,然后程序在那里运行 .get 命令或类似的东西。我为此工作了 7 个小时,但我无法让它工作。
【问题讨论】:
标签: python json api discord discord.py