pycord
pycord copied to clipboard
Fix tasks.loop
Summary
Make tasks.loop work for slash commands bots.
What is the feature request for?
discord.ext.tasks
The Problem
When i am trying to loop with the the slash commands bot it is not working.
here is the code.
import discord
from discord.ext import tasks
intents = discord.Intents()
intents.all()
bot = discord.Bot(intents=intents)
@tasks.loop(seconds=10)
async def loop():
print('loop')
loop.start()
bot.run(token)
The Ideal Solution
make the loop work like if you would use the regular commands bot.
The Current Solution
No response
Additional Context
No response
Task loops don't care if you are using discord.Bot or discord.Client, the example that you posted runs fine for me. I don't understand what you want fixed here.
For reference here is the output in my terminal after running your code:

probably won't work but try
import discord
from discord.ext import tasks
intents = discord.Intents()
intents.all()
bot = discord.Bot(intents=intents)
@client.event
async def on_ready():
loop.start()
@tasks.loop(seconds=10)
async def loop():
print('loop')
bot.run(token)
that's how i do it and it works for me, maybe it will work for you, who knows