【发布时间】:2020-10-03 05:22:19
【问题描述】:
一点背景
在学习了一点python之后,我一直在尝试制作一个discord bot作为我的第一个宠物项目。我的目标是从我一直在玩的在线游戏中检索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:])
【问题讨论】:
-
您是否尝试在您的代码中使用 Ctrl-F 来“发送”?你知道
await是什么吗? -
我确实添加了它
async def discord_display(end_data): await message.channel.send(end_data ) discord_display(['finally the dumbass succeded.LOL']),但得到了同样的信息 -
在你的
def discord_display中你必须像这样await message.channel.send(end_data) -
@Abdulaziz 我确实更改了代码。我更新了上面的代码。但它仍然给我同样的错误
标签: python discord.py coroutine