简体   繁体   English

Discord.py tasks.loop 不起作用,它没有返回错误

[英]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.我一直试图在 Discord.py 中创建循环,但我一直失败。 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.在 discord.py 中,您必须在创建的每个循环上调用 .start .start()方法。 In this case, add_seconds.start() .在这种情况下, add_seconds.start() Also, try adding global secondsUp to the top of your function definition.另外,尝试将global secondsUp添加到 function 定义的顶部。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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