簡體   English   中英

discord.py, RuntimeWarning: 啟用 tracemalloc 以獲取發送消息時的對象分配回溯

[英]discord.py, RuntimeWarning: Enable tracemalloc to get the object allocation traceback on sending message

好的,所以我遇到了這樣的問題:我編寫了一個代碼,旨在每隔 10 秒(現在,用於測試)在不和諧服務器上發送消息,當我嘗試在不和諧上執行命令時:

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)

一切都很好。 感謝您的幫助伙計們:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM