随机未确定



代码-

msg = message.content

if any(word in msg for word in sad_words):
await message.channel.send(random.choice(starter))

错误-

Traceback (most recent call last):
File "/home/runner/Dank-Village-Bot/venv/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "main.py", line 40, in on_message
await message.channel.send(random.choice(starter))
File "/nix/store/p21fdyxqb3yqflpim7g8s1mymgpnqiv7-python3-3.8.12/lib/python3.8/random.py", line 291, in choice
return seq[i]
TypeError: 'set' object is not subscriptable

不幸的是,你不能在集合上使用random.choice,你必须制作一个列表副本才能完成

starter_list = list(starter)
random.choice(starter_list)

最新更新