Python Discord.py异步函数不提供任何输出,也不执行任何操作

Python Discord.py异步函数不提供任何输出,也不执行任何操作,python,discord,discord.py-rewrite,Python,Discord,Discord.py Rewrite,代码如下: print('hmm1') #testing, this one prints import discord from discord.ext import commands client = commands.Bot(command_prefix='&') client.run('my token', bot=False) async def testFunction(): print('hmm') #<- this one does not print.

代码如下:

print('hmm1') #testing, this one prints
import discord
from discord.ext import commands
client = commands.Bot(command_prefix='&')
client.run('my token', bot=False)

async def testFunction():
    print('hmm') #<- this one does not print.
    channel = await client.get_channel(708848617301082164)
    message_id=715307791379595275
    msg = await client.get_message(channel, message_id)
    await msg.edit(content="L")
    await msg.edit(content="W")
    print('edited message!')
testFunction()
# none of the above works. I only get "hmm1" printed in console.
print('hmm1')#测试,这一个打印
进口不和
从discord.ext导入命令
client=commands.Bot(命令前缀='&')
client.run('my token',bot=False)
异步def testFunction():

print('hmm')#如果您不熟悉异步函数,则需要对它们进行
wait
ed。协同程序的示例可以在
msg.edit(…
)中看到,因为
edit()
是一个协同程序,因此您需要
wait
像这样:
wait testFunction()

此外,
client.get\u channel()
client.get\u message()
不是协同路由,因此不需要等待它们

正如Eric提到的,您还需要将
客户端移动到文件的最后一行,否则它将阻止脚本的其余部分。下面是代码的结构:

#导入
#命令、事件、函数
#最后一行
client.run('。。。

看起来您也在使用一些旧文档,因为d.py已经转移到重写(v1.x),而且您使用的
client.get_message()
似乎实际上来自

我想好好读一读,熟悉一下重写。尽量避免过时的教程

作为一个小起点,您的
等待客户端。获取消息(频道,消息id)
应该变成
等待频道。获取消息(消息id)


参考文献:


如果您不熟悉异步函数,则需要对它们进行
wait
ed。协同程序的示例可以在
msg.edit(…
)中看到,因为
edit()
是一个协同程序,因此您需要
wait
像这样:
wait testFunction()

此外,
client.get\u channel()
client.get\u message()
不是协同路由,因此不需要等待它们

正如Eric提到的,您还需要将
客户端移动到文件的最后一行,否则它将阻止脚本的其余部分。下面是代码的结构:

#导入
#命令、事件、函数
#最后一行
client.run('。。。

看起来您也在使用一些旧文档,因为d.py已经转移到重写(v1.x),而且您使用的
client.get_message()
似乎实际上来自

我想好好读一读,熟悉一下重写。尽量避免过时的教程

作为一个小起点,您的
等待客户端。获取消息(频道,消息id)
应该变成
等待频道。获取消息(消息id)


参考文献:


testFunction()
永远不会运行。
client.run
挂起。我建议您实际查看文档和API的工作原理。
client.run()
是一个阻塞调用,意味着它停止执行。请尝试
等待client.start()
testFunction()
永远不会运行。
client.run
挂起。我建议您实际查看文档和API的工作原理。
client.run()
是一个阻塞调用,意味着它会停止执行。请尝试
wait client.start()
@A68AGaming还有哪些问题?@A68AGaming还有哪些问题?