Heyo guys,
So currently i'm trying to get a Discord bot to work, which uses asyncio, and an API which uses a yield function inside an event loop.
I'm trying to get a value from an api and the line on 17 does actually print a value, however at line 41 it sais that ret_mess is null.
I'm not sure what to do at this point:
So currently i'm trying to get a Discord bot to work, which uses asyncio, and an API which uses a yield function inside an event loop.
I'm trying to get a value from an api and the line on 17 does actually print a value, however at line 41 it sais that ret_mess is null.
I'm not sure what to do at this point:
import discord
import asyncio
import r6sapi as api
TOKEN = 'XXX'
client = discord.Client()
auth = api.Auth('XXX', 'XXX')
ret_mess = "";
@asyncio.coroutine
def get_kills(name, operator):
global ret_mess
player = yield from auth.get_player("TryingDutchman_", api.Platforms.UPLAY)
operator = yield from player.get_operator("hibana")
print(operator.kills)
ret_mess = str(operator.kills)
def get_player(name):
player = yield from auth.get_player(name, api.Platforms.UPLAY)
operator = player.__next__().get_operator("sledge");
return operator;
@client.event
async def on_message(message):
global ret_mess
if message.author == client.user:
return
if message.content.startswith('!hello'):
msg = 'Hello {0.author.mention}'.format(message)
await client.send_message(message.channel, msg)
if message.content.startswith('!update'):
try:
asyncio.get_event_loop().run_until_complete(get_kills(message.author.display_name, "hibana"))
except:
print("ret: " + ret_mess)
pass
await client.send_message(message.channel, ret_mess)
@client.event
async def on_ready():
global auth
print('Logged in as')
print(client.user.name)
print('------')
client.run(TOKEN)
