python - 从列表中获取随机元素(在其他文件中)
问题描述
(对不起我的英语:V)我正在用 discord.py 制作一个不和谐的机器人。
import random
class List():
list = [
"very"
"big"
"list"
]
def choice(self, list):
result = random.choice(list)
return result
这不是那个列表(它非常大)。我必须从这个列表中选择随机元素。
import List
list = List
@bot.command
async def send(ctx):
element = list.choice(list)
ctx.send(element)
buuuut 它引发了一个异常:
RuntimeWarning: coroutine 'Messageable.send' was never awaited
ctx.send(element)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
解决方案
ctx.send
是协程而不是常规函数,您需要等待它。所以:await ctx.send(...)
是正确的语法
推荐阅读
- sql-server - SQL Server TRY/CATCH 中的内部消息
- javascript - Kartik gridview,浮动标题thead和tbody不一样,yii2
- android - 错误:程序类型已存在:android.support.v4.app.INotificationSideChannel$Stub
- javascript - 如何从另一个域获取 Azuracast 的歌曲信息?
- c# - 跟踪在 MVVM 中选择了哪些按钮?
- react-native - 在 TouchableOpacity 的 onPress 中调用时未正确等待异步 Action-Creator
- android - 在这种情况下,为什么android会杀死将光标放在另一个进程上的内容提供者上的客户端进程?
- javascript - 我正在尝试在导航栏中添加带有引导类的 home glyphicon。但它没有显示在输出页面中。任何修复?
- html - Repeat two rows pattern in CSS Grid
- c++ - 关于从 CRgn 对象中提取点的查询