【发布时间】:2021-09-01 08:07:19
【问题描述】:
我自己做一个随机数命令,例子:
我:{commandprefix}随机
Bot : 请输入两个参数,一个数字和一个更大的数字。
我:{commandprefix}随机 1
Bot : 请输入两个参数,一个数字和一个更大的数字。
我:{commandprefix}随机 0.5 1.3
机器人:0.8
我:{commandprefix}随机 1 10
机器人:3
等等
就像我的例子一样,如果有任何错误(比如字符不是数字,只有 1 个参数等),机器人会自动告诉我们有错误。
这是我的代码:)
@client.command()
async def random(ctx, arg1, arg2):
import random
try:
import random
arg = random.randrange(float(arg1), float(arg2))
else:
embed = discord.Embed(title = "Random Number",
description = f"Here is your random number : {arg}",
color = discord.Color.red())
now = datetime.now()
current_time = now.strftime("%H:%M")
embed.set_footer(text=f"Requested by {ctx.author} at {current_time}")
await ctx.send(embed=embed)
它只能发送不是小数的随机数并且还不能检测到错误:(
【问题讨论】:
-
什么用户?你,程序员?还是与机器人交互的不和谐用户(客户端)?你想怎么说?使用通知?
-
如果你正在处理错误,它的here
标签: python discord discord.py bots