【发布时间】:2022-08-21 10:33:09
【问题描述】:
import discord.ext
import discord
from discord.ext import commands
from discord.ext import tasks
from keep_alive import keep_alive
import os
import schedule
client = discord.Client()
client = commands.Bot(command_prefix=\"\")
channel_id = 927272717227528262
channel = client.get_channel(channel_id)
@tasks.loop(seconds=1.0)
@client.event
async def on_message(message):
if message.author == client.user:
return
def job2():
await message.channel.send(\"message\")
schedule.every(10).seconds.do(job2)
while True:
schedule.run_pending()
time.sleep(0)
keep_alive()
client.run(os.getenv(\'TOKEN\'))
每次我运行它时,我都会得到:
SyntaxError: \'await\' outside async function
我也遇到消息未定义job2 的定义的问题,即使它只是在上面的行中定义。
-
您永远不会在 async 函数内部等待。以后不能在 job2() 中调用它。它必须在 async def 中
标签: discord discord.py