jokes = [
('Can a kangaroo jump higher than a house?', 'Of course, a house doesn’t jump at all.'),
('Anton, do you think I’m a bad mother?', 'My name is Paul.'),
('Why can\'t cats work with a computer?', 'Because they get too distracted chasing the mouse around, haha!'),
('My dog used to chase people on a bike a lot.', 'It got so bad, finally I had to take his bike away.'),
('What do Italian ghosts have for dinner?', 'Spook-hetti!')]
setup, punchline = random.choice(jokes)
await client.send_message(message.channel, setup)
await asyncio.sleep(3)
await client.send_message(message.channel, punchline)
2条答案
按热度按时间tkqqtvp11#
你根本不应该使用
time.sleep
,因为它不适合asyncio
,而discord.py
是基于asyncio
构建的。相反,我们应该有一个配对列表,随机选择一个,然后使用asyncio.sleep
在消息之间暂停。vi4fp9gy2#
你的做法全错了。
将不工作,原因是因为你想
time.sleep(3)
是一个字符串,对于每一个这些你会从(据我所知).需要做以下当然,您需要将bot更改为客户端,但这基本上是您必须做的。
不起作用的原因:执行
a = "string" +func()+"string2 ; print(a)"
会给予错误,因为您将其视为字符串。