一点背景
在学习了一点python之后,我一直在尝试将discord机器人作为我的第一个宠物项目。我的目标是从我一直在玩的在线游戏中检索API数据,并将其粘贴到我的discord服务器上。我需要检索的数据的玩家ID由discord命令提供。例如:!stats 2255880
是一个命令,其中2255880是游戏中的玩家ID。我几乎已经完成了代码,除了我不断得到的地狱般的错误和谷歌没有帮助我太多
错误:
RuntimeWarning: coroutine 'Messageable.send' was never awaited
message.channel.send(end_data )
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
#to import modules
import discord
from discord.ext import commands
from discord.ext.commands import Bot
import requests
import json
#client for bot
client=discord.Client()
######## TORN API DATA #########
apikey='insert key here'
@client.event
async def on_message(message):
if message.content.startswith('!stats'):
def torn_script(player_ID):
apiurl='https://api.torn.com/user/'+str(player_ID)+'?selections=personalstats&key='+apikey
r=requests.get(apiurl)
astext=r.text
asdict=json.loads(astext)
data=json.loads(requests.get(apiurl).text)['personalstats']
print('attacks won: ',data['attackswon'])
async def discord_display(end_data):
await message.channel.send(end_data )
discord_display(['finally the dumbass succeded.LOL'])
torn_script(message.content[6:])
由于
discord_display
是一个协程(async def discord_display()
),您需要等待它:PS:如果您导入了^{,为什么仍然使用
discord.Client
?{a1}扩展方式更加实用和强大相关问题 更多 >
编程相关推荐