如何在命令中添加space? discord.js
how to add space in commands? discord.js
我希望我的命令包含一个 space,例如
$ sudo faq mod
(注意space)
但这似乎行不通,我通常不得不这样做
faq_mod
代替。
这是我的代码,但是 space 不起作用。
const { Client, Intents } = require('discord.js');
const Discord = require('discord.js');
const mongoose = require('mongoose')
require('dotenv').config();
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
const prefix = '$ sudo ';
const fs = require('fs');
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.once('ready', async () => {
console.log(`Logged in as ${client.user.tag}!`);
client.user.setActivity('$ sudo help | heckbot.ml');
await mongoose.connect(process.env.MONGO_URI, {
keepAlive: true,
})
})
client.on('message', message => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/)
const command = args.shift().toLowerCase();
if (command === 'ping') {
client.commands.get('ping').execute(message, args);
} else if (command === 'info') {
client.commands.get('info').execute(message, args);
} else if (command === 'website') {
client.commands.get('website').execute(message, args);;
} else if (command === 'help') {
client.commands.get('help').execute(message, args);
} else if (command === 'youtube') {
client.commands.get('youtube').execute(message, args);
} else if (command === 'invite') {
client.commands.get('invite').execute(message, args);
} else if (command === 'kick') {
client.commands.get('kick').execute(message, args);
} else if (command === 'ban') {
client.commands.get('ban').execute(message, args);
} else if (command === 'clear') {
client.commands.get('clear').execute(message, args);
} else if (command === 'faq mod') {
client.commands.get('faq_mod').execute(message, args, Discord);
}
});
client.login(process.env.TOKEN)
请帮帮我
在检查命令时不能包含空格,因为在定义 args 时会用空格“拆分”字符串。
行
const args = message.content.slice(prefix.length).split(/ +/)
将删除前缀并将生成的字符串拆分为空格。 (例如:“早上好”变成[“好”,“早上好”])。要检查两个连续的参数,你可以做
if(command == "faq" && args[0] == "mod")
我希望我的命令包含一个 space,例如
$ sudo faq mod
(注意space)
但这似乎行不通,我通常不得不这样做
faq_mod
代替。
这是我的代码,但是 space 不起作用。
const { Client, Intents } = require('discord.js');
const Discord = require('discord.js');
const mongoose = require('mongoose')
require('dotenv').config();
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
const prefix = '$ sudo ';
const fs = require('fs');
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.once('ready', async () => {
console.log(`Logged in as ${client.user.tag}!`);
client.user.setActivity('$ sudo help | heckbot.ml');
await mongoose.connect(process.env.MONGO_URI, {
keepAlive: true,
})
})
client.on('message', message => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/)
const command = args.shift().toLowerCase();
if (command === 'ping') {
client.commands.get('ping').execute(message, args);
} else if (command === 'info') {
client.commands.get('info').execute(message, args);
} else if (command === 'website') {
client.commands.get('website').execute(message, args);;
} else if (command === 'help') {
client.commands.get('help').execute(message, args);
} else if (command === 'youtube') {
client.commands.get('youtube').execute(message, args);
} else if (command === 'invite') {
client.commands.get('invite').execute(message, args);
} else if (command === 'kick') {
client.commands.get('kick').execute(message, args);
} else if (command === 'ban') {
client.commands.get('ban').execute(message, args);
} else if (command === 'clear') {
client.commands.get('clear').execute(message, args);
} else if (command === 'faq mod') {
client.commands.get('faq_mod').execute(message, args, Discord);
}
});
client.login(process.env.TOKEN)
请帮帮我
在检查命令时不能包含空格,因为在定义 args 时会用空格“拆分”字符串。
行
const args = message.content.slice(prefix.length).split(/ +/)
将删除前缀并将生成的字符串拆分为空格。 (例如:“早上好”变成[“好”,“早上好”])。要检查两个连续的参数,你可以做
if(command == "faq" && args[0] == "mod")