【问题标题】:How to remove part of a command when 'shouting'?“大喊”时如何删除部分命令?
【发布时间】:2018-11-10 17:06:13
【问题描述】:
if (message.content.toLowerCase().startsWith(prefix + `shout`)) {
  if (!message.member.roles.some(r => ["shout perms"].includes(r.name)))
    return message.reply("Sorry, you don't have permissions to use this!");

  if (!args) {
    return;
    message.reply('Please specify a message to shout.')
  }
  const shoutMSG = args.join(" ");

  roblox.shout(groupId, shoutMSG)
    .then(function() {
      console.log(`Shouted ${shoutMSG}`);

    })
  message.channel.sendMessage(`Shouted ${shoutMSG}`)
    .catch(function(error) {
      console.log(`Shout error: ${error}`)
    });
}

上面是代码,当使用命令时,会向 Roblox 发送一个喊叫,但是,它也会喊出前缀和命令,如下所示。我该如何解决这个问题,让它只喊消息而不是前缀和命令?

【问题讨论】:

  • const shoutMSG = args.slice(1).join(" "); 大概。
  • 这是 discord.js 还是 roblox?
  • @ElectroxMortem Discord.js 与 Roblox-js 包。
  • 好吧。我看到您遵循了我的潜意识信息并将我标记为正确? ;) @ScottElsy

标签: javascript node.js discord.js


【解决方案1】:

您只需要剪掉前 7 个字符。 1 为前缀。 5个喊叫,1个空格

var shoutMSG = '!shout Please mark this as correct'
console.log(shoutMSG)
shoutMSG = shoutMSG.substr(7)
console.log(shoutMSG)

【讨论】:

    猜你喜欢
    • 2016-07-12
    • 2021-07-30
    • 2021-05-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-06
    • 2014-10-31
    • 1970-01-01
    • 2017-08-23
    相关资源
    最近更新 更多