python - discord.py,RuntimeWarning:启用 tracemalloc 以在发送消息时获取对象分配回溯
问题描述
好的,所以我遇到了这样的问题:我编写了一个代码,该代码旨在每隔 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
解决方案
好的,谢谢@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)
一切都很好。感谢您的帮助伙计们:)
推荐阅读
- laravel - 我的模态引导程序存在但不可见
- javascript - 调用带参数的函数的reactJS渲染无法编译
- python - 检查索引中的任何缺失日期
- google-bigquery - Apache Beam/Google Dataflow PubSub 到 BigQuery 管道:处理插入错误和意外重试行为
- laravel - Laravel 更改存储控制器功能的参数
- spring-boot - Spring Boot 数据源未创建 JNDI
- java - 执行主类时如何使bash自动完成java限定类名
- python - 如何从原始图像尺寸计算内核尺寸?
- java - 抛出 RuntimeException 时,Java 期望返回值
- angular - Azure 广告发现密钥在一段时间后不起作用