【问题标题】:How do I make this slash command respond to a certain string如何让这个斜杠命令响应某个字符串
【发布时间】:2022-08-24 10:55:50
【问题描述】:

让我解释一下我在这里想要实现的目标。我正在努力做到这一点,以便如果用户执行某行代码,他们将获得一个自定义字符串,例如如果有人说 \'ping\' 它会说 \'pong\' 并且如果有人说 \'hi \'它会说\'你好\'。

我已经多次尝试完成这项工作,但我无法将我的婴儿大脑包裹在它周围。

const ms = require(\'ms\');
const { ApplicationCommandType, ApplicationCommandOptionType } = require(\'discord.js\');

module.exports = {
    name: \'console\',
    description: \'Developer Mode!\',
    voiceChannel: false,
    options: [
    {
        name: \'Code\',
        description: \'A line of code you wish to execute\',
        type: ApplicationCommandOptionType.String,
        required: true,
    }
    ],
async execute({ inter }) {
    const LineOfCode = ms(inter.options.getString(\'Code\'));

    const embed = new EmbedBuilder()
    .setColor(\'#5679EF\')
    .setAuthor({ name: client.user.username, iconURL: client.user.displayAvatarURL({ size: 1024, dynamic: true }) })
    .setTitle(\"???? Console\")
    .setDescription(`${LineOfCode} Execution Successfully`)

},
};

^ 代码不完整,因为我对 Discord.js v14 缺乏经验

哦,最后一件事,如果没有列出用户在选项框中输入的字符串,我希望它也能说出一些自定义的内容:)

我希望它工作的一个例子是:/console ping回复:pong(嵌入) 或者/console hi回复:你好(嵌入)

如果您输入的内容不在列表中,您可以说:/console cake回复:这个不可用! (嵌入)

  • 澄清一下是 \"code\" 选项一个例子还是你试图添加到 \"code\" 选项?
  • 那么斜杠命令是否应该为该字符串启动一个侦听器,或者您是否尝试将所有操作合二为一,例如 /console ping 或只是 /console 然后它等待字符串?
  • 我正在尝试添加到代码选项
  • 我想一次性完成
  • @Gh0st 对不起,我是这个网站的新手 lmao 忘了给你们打电话

标签: javascript discord discord.js bots


【解决方案1】:

这对我有用;

    const DiscordifyCredits = new EmbedBuilder()
      .setColor('#0CEC1D')
      .setAuthor({ name: client.user.username, iconURL: client.user.displayAvatarURL({ size: 1024, dynamic: true }) })
      .setTitle('? Console')
      .setDescription("```CodeBean's Discordify\n\nCoke (Team CodeBean)\nRakin (Additional Help)\nClorophyte (Team CodeBean)\nEdfour10 (Team CodeBean)\nVoltrex (Additional Help)\nSayuri (Additional Help)\nCollin (Additional Help)\n\nSpecial Thanks:\nDiscord\nNonay\nMethod Gaming\nToast_carno (Bug Testing)\nnerd (Bug Testing)```")
      .setFooter({ text: 'Powered by Nonay', iconURL: inter.member.avatarURL({ dynamic: true })});
    
      const text = inter.options.getString('code');
    
      switch (text) {
        case "import = discordify print(credits)":
        await inter.reply({ embeds: [DiscordifyCredits] })
        break;
        case 'baz':
        await inter.reply({ content: 'biz' });
      }
    
    },
    };

【讨论】:

    猜你喜欢
    • 2021-07-17
    • 1970-01-01
    • 1970-01-01
    • 2022-11-10
    • 2019-09-18
    • 1970-01-01
    • 1970-01-01
    • 2019-07-10
    • 2013-06-20
    相关资源
    最近更新 更多