我正在尝试通过pip discord.py建立discord bot。在命令!random之后我想问用户任何号码,然后机器人将生成0和输入数字之间的随机数。它对我来说并不合适,因为我对discord.py一无所知,我问那里:)
代码:
import random
elif message.content.startswith("!random"):
await client.send_message(message.channel, "Enter a number: ")
num = await client.wait_for_message(int)
numm = int(num)
randomnum = random.randint(0, numm)
await client.send_message(message.channel, randomnum)
答案 0 :(得分:0)
试试这个:
import random
elif message.content.startswith("!random"):
await client.send_message(message.channel, "Enter a number: ")
def check(msg):
return msg.content
reaction.content = await client.wait_for_message(author=message.author, check=check)
numm = int(reaction)
randomnum = random.randint(0, numm)
await client.send_message(message.channel, randomnum)
您还应该检查反应是否为int
(添加了squaswin的反应。请注意,代码未经过测试)