python - 为什么函数会出错?不和谐.py
问题描述
def test():
await message.author.send('ehy')
@bot.event
async def on_message(message):
if message.author.id == 2980828228298:
test()
我不明白为什么这个简单的功能不起作用。错误是“等待”。有什么帮助吗?
解决方案
我不是discord.py
高手,其实我什么都不知道。虽然我确实理解为了使用await
它必须在async
函数内部。使用您提供的代码,我想您可以在test()
函数中返回一个字符串。
def test():
return 'ehy'
@bot.event
async def on_message(message):
if message.author.id == 2980828228298:
await message.author.send(test())
推荐阅读
- python - 如何创建一个变量并将其存储为 50 个观察值(python)?
- java - WildFly 服务模块加载器 - jdk.incubator.http.HttpClient 上的 ClassNotFound
- php - 有没有办法用关系表中的最小值检查多个匹配项?
- python - 从另一列中的每一行单元格中搜索字符串,如果找到匹配项,则在 pandas 中找到的匹配项下方插入行
- flutter - 如何让 SliverAppBar 在 sub_page 的 SliverList 之前滚动
- html - 如何在 Ionic 3 中水平对齐两个单选按钮
- javascript - 如何使用 express ntlm 实现用户名/密码验证?
- angular - 有没有办法从 angularJS 在 HDInsight 集群中运行配置单元查询?
- rabbitmq - RabbitMQ:当消费者关闭时发布消息,以后消费者不能在没有命名队列的情况下消费消息
- angular - Angular 服务构造函数阻塞单元测试