Discord.py client.say在事件循环任务中不起作用

时间:2019-01-27 00:31:04

标签: python python-3.x discord.py

我正在将discord.py用于机器人,并试图使设置功能在后台运行,而其他功能也在运行。它似乎正在运行,但是该程序在client.say处停止(打印a但不打印b)。我也没有任何错误。

async def setup():
    embed = discord.Embed(title='Setting game up...',colour=0xff66ff)
    print('a')
    setupmsg = await client.say(embed=embed)
    print('b')
    #send message for each person
    for i in USER_LIST:
        embed = discord.Embed(title=f"{i.name}",colour=0xff66ff)
        msg = await client.say(embed=embed)
        await client.add_reaction(message=msg,emoji='\u2705')
        await client.add_reaction(message=msg,emoji='\u274E')
        await client.add_reaction(message=msg,emoji='\u2754')
        await client.add_reaction(message=msg,emoji='\U0001F31F')
    await client.delete_message(setupmsg)

1 个答案:

答案 0 :(得分:0)

根据documentation,您不能在await client.say()之外有@client.command()

您可以尝试将message参数从事件传递到coro并使用send_message()代替

类似

@client.event
async def on_message(message):
  if message.author != client.user:
    await setup(message)

async def setup(message):
  USER_LIST = message.server.members
  embed = discord.Embed(title='Setting game up...',colour=0xff66ff)
  print('a')
  setupmsg = await client.send_message(message.channel,embed=embed)
  print('b')
  #send message for each person
  for i in USER_LIST:
    embed = discord.Embed(title=f"{i.name}",colour=0xff66ff)
    msg = await client.send_message(message.channel,embed=embed)
    await client.add_reaction(message=msg,emoji='\u2705')
    await client.add_reaction(message=msg,emoji='\u274E')
    await client.add_reaction(message=msg,emoji='\u2754')
    await client.add_reaction(message=msg,emoji='\U0001F31F')
  await client.delete_message(setupmsg)