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还有哪些问题?