【问题标题】:How do you add arguments for the event interactionCreate in discord.js V13如何在 discord.js V13 中为事件交互创建添加参数
【发布时间】:2021-08-21 02:15:08
【问题描述】:

我最近从 discord.js V12 切换到了 discord.js V13

如何为斜杠命令添加参数?
例如:/verify UsernameHere

我正在尝试制作一个验证系统,因为我对斜杠命令非常感兴趣。
任何帮助表示赞赏;谢谢!

【问题讨论】:

    标签: node.js discord.js


    【解决方案1】:

    斜线命令具有选项,您可以使用以下类型对其进行设置:

    SUB_COMMAND 将选项设置为子命令
    SUB_COMMAND_GROUP 将选项设置为子命令组
    STRING 将选项设置为需要字符串值
    INTEGER 设置选项需要整数值
    NUMBER 设置选项以需要小数(也称为浮点)值
    BOOLEAN 设置选项以需要布尔值
    USER 设置选项要求用户或雪花作为值
    CHANNEL 设置选项以要求频道或雪花作为值
    ROLE 设置选项以要求角色或雪花作为值
    MENTIONABLE 设置要求用户、角色或雪花作为值的选项

    您可以在guides option types查看它们

    所以现在要回复他们,您需要解析选项,您可以在 guides-parsing-options 找到详细说明

    const string = interaction.options.getString('input');
    const integer = interaction.options.getInteger('int');
    const number = interaction.options.getNumber('num');
    const boolean = interaction.options.getBoolean('choice');
    const user = interaction.options.getUser('target');
    const member = interaction.options.getMember('target');
    const channel = interaction.options.getChannel('destination');
    const role = interaction.options.getRole('muted');
    const mentionable = interaction.options.getMentionable('mentionable');
    
    console.log([string, integer, boolean, user, member, channel, role, mentionable]);
    

    斜杠命令示例:

    const data = {
      name: "verify", // no uppercase, else you will get an error
      description: "Example description",
      options: [{
        name: "username", // no uppercase as well
        description: "example option description",
        type: "USER"
      }]
    }
    

    希望对您有所帮助! :)

    【讨论】:

    • 如果我没记错的话,我以为options应该是一个数组?
    • 如果它是一个选项,我想它可以直接是一个 obj,虽然我没有真正测试它,但是如果它不起作用,我会编辑我的答案,谢谢你提醒我!
    猜你喜欢
    • 2022-01-04
    • 2022-01-05
    • 2022-09-30
    • 2021-10-17
    • 1970-01-01
    • 1970-01-01
    • 2020-03-12
    • 1970-01-01
    相关资源
    最近更新 更多