client.loop.create_task
should still work fine with the rewrite
version. Example of a background task in the rewrite
version can be found here.
from discord.ext import commands
import asyncio
client = commands.Bot(command_prefix='!')
async def background_task():
await client.wait_until_ready()
counter = 0
channel = client.get_channel(123456) # Insert channel ID here
while not client.is_closed():
counter += 1
await channel.send(counter)
await asyncio.sleep(10)
client.loop.create_task(background_task())
client.run('token')
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…