简体   繁体   中英

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

Ok so I have a problem like this: I wrote a code that's meant to send message on discord server every(just for now, for testing) 10 seconds, and when I try to execute command on 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()

Every time I get error like this:

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

Okay, thank you @FrozenAra and @derw for your help, although I found a tottaly different way of solving the problem I used discord.Client library and Tasks so now it looks like this:

@tasks.loop(minutes=30)
async def reminder():
    channel = client.get_channel(692724253237313576)
    await channel.send("So what?")
    await channel.send(preembed)

And everything works just great. Thanks for your help Guys :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM