代码如下:
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.
我不知道发生了什么,因为控制台中没有任何错误或输出。有人知道这个问题吗
如果您不熟悉异步函数,则需要对它们进行
await
处理。可以在msg.edit(...
中看到协同路由的示例,因为edit()
是一个协同路由,因此您需要像这样await
处理:await testFunction()
另外,
client.get_channel()
和client.get_message()
不是协程,因此不需要等待它们正如Eric提到的,您还需要将
client.run('...
向下移动到文件中的最后一行,否则它将阻止脚本的其余部分。下面是代码的结构:看起来您也在使用一些旧文档,因为d.py已经转移到rewrite(v1.x),并且看起来您使用的
client.get_message()
实际上来自v0.16.x我想读一下these changes以熟悉重写。尽量避免过时的教程
作为一个小起点,您的
await client.get_message(channel, message_id)
应该变成await channel.fetch_message(message_id)
参考文献:
相关问题 更多 >
编程相关推荐