[英]Programming a Discord bot in Python- Having issues with Aync Praw
[英]Programming a Discord bot in Python- Having issues with Schedule API
我试图让我的机器人定期发送消息,但遇到了一些问题。 这是我的代码:
def job():
channel = client.get_channel(806740247009296445)
await channel.send("I'm working...")
schedule.every(10).seconds.do(job)
while True:
schedule.run_pending()
time.sleep(1)
当我尝试这个时,它给了我一个错误SyntaxError: invalid syntax
on the line with await channel.send
。 我也尝试使用await ctx.channel.send
,但这告诉我TypeError: job() missing 1 required positional argument: 'ctx'
。
我不确定为什么会发生这种情况,任何见解将不胜感激。
await
关键字, job
function是正常的,同步function,不是协程job
设为协程,您也必须await
它,正如我之前所说,您只能在另一个协程中等待time.sleep
相同一次修复所有错误的最简单方法是使用 discord.py 扩展tasks
from discord.ext import tasks
@tasks.loop(seconds=10)
async def job():
channel = client.get_channel(806740247009296445)
await channel.send("I'm working...")
job.start()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.