简体   繁体   中英

Discord.py tasks.loop does not work and it returns no errors

I've been trying to make loops in Discord.py, but I keep failing. What makes it harder is that it returns no errors.

This is the code;

import discord
import datetime
import time
import threading
import os
import json
import random
import asyncio
from discord.ext import commands
from discord.ext.commands import has_permissions
from discord.ext.tasks import loop
import keep_alive

prefix = "s."
token = str(os.getenv("TOKEN"))
client = commands.Bot(command_prefix = prefix)
client.remove_command("help")
os.chdir(r".")
ownerId = [219567539049594880]
logChn = 705181132672729098
secondsUp = 0

@loop(seconds=1)
async def add_second():
    secondsUp+=1
    print("+1 Second")

The console does not print anything. No errors. Is there anything I'm missing?

In discord.py, you must call the .start() method on every loop that you create. In this case, add_seconds.start() . Also, try adding global secondsUp to the top of your function definition.

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