即使未正确调用,Discord 机器人也能够发送消息

时间:2021-03-01 17:54:08

标签: discord.py

我正在尝试制作一个不和谐的机器人,但我想知道如何制作它,以便如果用户没有正确调用它而将其留空,它仍然会发送消息。我的意思是,如果有人执行 //changelogs (number),那么如果用户在 (number) 中输入一个数字,机器人就会发送此版本的更改日志。但是,如果用户只是调用 //changelogs,它会显示一条消息,说明用户可以调用哪些版本的变更日志。

1 个答案:

答案 0 :(得分:0)

@commands.command()
async def changelogs(ctx: Context, number: int = None):
    if number is None:
        await ctx.send("a message of what versions of changelogs the user can call")
    else:
        await ctx.send("the changelogs of this version")

参考资料:

commands.command : https://discordpy.readthedocs.io/en/latest/ext/commands/api.html?highlight=commands%20command#discord.ext.commands.command

Context : https://discordpy.readthedocs.io/en/latest/ext/commands/api.html?highlight=context#discord.ext.commands.Context

输入:https://docs.python.org/3/library/typing.html