discord.js说命令实际上说“说". [英] discord.js say command actually says "say"

查看:27
本文介绍了discord.js说命令实际上说“说".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我开始使用模块并清理代码之前,我对say命令从未遇到过任何问题,但是由于我的命令很少出现错误.我试图弄清楚为什么要说这个命令.

I've never had a problem with the say command until I start using modules and cleaned up my code but since I have few my commands have bugged. I'm trying to figure out why it is saying the command.

const commandFiles = fs
  .readdirSync("./commands/")
  .filter(file => file.endsWith(".js"));
for (const file of commandFiles) {
  const command = require(`./commands/${file}`);

  bot.commands.set(command.name, command);
}

bot.on("message", async message => {
  if (!message.content.startsWith(PREFIX)) return;
  let args = message.content.substring(PREFIX.length).split(" ");

  switch (args[0]) {

    case "say":
      bot.commands.get("say").execute(message, args);
      break;

const Discord = require("discord.js");

module.exports = {
  name: "say",
  description: "Show's avatar",
 async execute(message, args){

    const sayMessage = args.join(" ");
    message.delete().catch(O_o => {});
    message.channel.send(`${sayMessage} - ${message.author}`);
  }
}

提前谢谢!

推荐答案

代码正好按照您对其的编程目的进行了操作,

The code is doing exactly what you programmed it to, be it not intended.

let args = message.content.substring(PREFIX.length).split(" "); // args = ['say', 'Hello', 'World']

bot.commands.get("say").execute(message, args); // Passing in the entire args array

const sayMessage = args.join(" "); // sayMessage = 'say Hello World'

众多解决方案之一:

let args = message.content.substring(PREFIX.length).split(" ");
const command = args.splice(0, 1); // args now only contains the arguments

switch (command) {
  ...
}

这篇关于discord.js说命令实际上说“说".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆