好的,我有一个这样的问题:我写了一段代码,打算每隔10秒(现在只是为了测试)在discord服务器上发送一次消息,当我试图在discord上执行命令时:
import os
import sched
import time
from discord.ext import commands
from dotenv import load_dotenv
import Library
load_dotenv()
TOKEN = os.getenv('discordToken')
bot = commands.Bot(command_prefix='Question')
lastEmbed = None
s = sched.scheduler(time.time, time.sleep)
async def do_something(sc):
channel = bot.get_channel(416238248445214720)
await channel.send("And what?")
s.enter(10, 1, do_something, (sc,))
@bot.event
async def on_ready():
print(f'{bot.user.name} has connected to Discord!')
s.enter(10, 1, do_something, (s,))
s.run()每次我得到这样的错误:
C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\sched.py:151: RuntimeWarning: coroutine 'do_something' was never awaited
action(*argument, **kwargs)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback发布于 2020-10-14 03:44:28
好的,感谢@FrozenAra和@derw的帮助,尽管我发现了一种完全不同的方法来解决这个问题,我使用了discord.Client库和任务,所以现在看起来是这样的:
@tasks.loop(minutes=30)
async def reminder():
channel = client.get_channel(692724253237313576)
await channel.send("So what?")
await channel.send(preembed)一切都运行得很好。感谢你们的帮助:)
https://stackoverflow.com/questions/64340723
复制相似问题