Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 不协调的任务。韩元';不运行任务_Python_Discord.py_Discord.py Rewrite - Fatal编程技术网

Python 不协调的任务。韩元';不运行任务

Python 不协调的任务。韩元';不运行任务,python,discord.py,discord.py-rewrite,Python,Discord.py,Discord.py Rewrite,我需要以下代码的帮助: import discord from discord.ext import commands, tasks import os TOKEN = "tokenthing" client = commands.Bot(command_prefix="$$") @client.event async def on_ready(): test.start() print("Succesful L

我需要以下代码的帮助:

import discord
from discord.ext import commands, tasks
import os

TOKEN = "tokenthing"
client = commands.Bot(command_prefix="$$")
@client.event
async def on_ready():
        test.start()
        print("Succesful Login as {0.user}".format(client))
        


@client.command()
async def GiveMoney(ctx, user : discord.User, value : int):
        if value <= 0:
                await ctx.send("Can't send negative money.")
                return
        else:
                pass
        
        sender = str(ctx.author)
        reciever = str(user)

        if os.path.exists(sender+".txt"):
                pass
        else: 
                await ctx.send("You Don't have an account. Type $$CreateAccount to create one.")
                return

        if os.path.exists(reciever+".txt"):
                pass
        else:
                await ctx.send("The Person you are trying to give money doesn't have a bank Account")
                return

        try:
                f= open(sender+".txt", "r")
                balance = f.read()
                f.close()
                balance = int(balance)
                balance = balance - value
                balance = str(balance)
                f = open(sender+".txt", "w")
                f.write(balance)
                f.close()
        except FileNotFoundError:
                await ctx.send("You don't have a Bank account. Type $$CreateAccount to create one.")
                return
        try:
                f = open(reciever+".txt", "r")
                balance = f.read()
                f.close()
                balance = int(balance)
                balance = balance + value
                balance = str(balance)
                f = open(reciever+".txt", "w")
                f.write(balance)
                f.close()
        except FileNotFoundError:
                await ctx.send("The Person You are sending money dosen't have an account")
        print("{0} sent {1} to {2}".format(sender, value, reciever))


@tasks.loop(seconds=10)
async def test(ctx):
        for i in range(10):
                print(i)




client.run(TOKEN)
导入不一致
从discord.ext导入命令、任务
导入操作系统
TOKEN=“tokenthing”
client=commands.Bot(command\u prefix=“$$”)
@客户端事件
_ready()上的异步定义:
test.start()
打印(“作为{0.user}成功登录”。格式(客户端))
@client.command()
异步def GiveMoney(ctx,用户:discord.user,值:int):

如果值只需在开始循环时添加
等待
。因为您的函数是异步的。例如:

@client.event
_ready()上的异步定义:
等待测试。开始()

Thx就是它干的