这是我的两个代码,它们位于单独的文件夹中,我尝试的是嵌入的消息可以与我的前缀一起使用,但是当我使用此命令时,我放置的字母,数字或符号都没有关系它后面是因为无论前缀如何,命令执行的方式都是相同的。
{
"token": "(my token)",
"prefix": "-"
}
const { Client, MessageEmbed } = require ("discord.js");
const client = new Client();
const MessageAttachment = require("discord.js");
const config = require("./config.json");
const Discord = require('discord.js');
const bot = new Discord.Client();
let prefix = config.prefix;
/////////////////BOT///////////////////
function doKissAction() {
var rand = [
'https://media2.giphy.com/media/G3va31oEEnIkM/giphy.gif',
'https://media.tenor.com/images/fbb2b4d5c673ffcf8ec35e4652084c2a/tenor.gif',
'https://media.giphy.com/media/ZRSGWtBJG4Tza/giphy.gif',
'https://media.giphy.com/media/oHZPerDaubltu/giphy.gif',
'https://acegif.com/wp-content/uploads/anime-kiss-m.gif',
'https://media.giphy.com/media/bm2O3nXTcKJeU/giphy.gif',
'https://media.giphy.com/media/nyGFcsP0kAobm/giphy.gif',
'https://media0.giphy.com/media/KH1CTZtw1iP3W/source.gif'
];
return rand[Math.floor(Math.random() * rand.length)];
}
client.on('message', message => {
let args = message.content.substring(prefix.length).split(" ");
switch (args[0]) {
case 'kiss':
if(!args[1] ) {
message.channel.send('¡Necesitas a alguien a quien besar!');
} else {
const personTagged = message.mentions.members.first();
const acceptedEmbed = new Discord.MessageEmbed()
.setTitle(':sparkles: :heart: ¡Que romantico! :heart: :sparkles: ')
.setImage(doKissAction())
.setColor(0xF086FF)
.setDescription('`' + message.author.username + '`' + ' ha besado a ' + '`' + personTagged.displayName + '`')
message.channel.send(acceptedEmbed);
// personTagged.send();
}
break;
}
})
答案 0 :(得分:0)
问题是您不检查它是否以前缀开头,而只是删除前缀
let args = message.content.split(" ");
let commandName = args[0];
if(!commandName.startsWith(prefix)) return;
commandName = commandName.slice(prefix.length);
switch(commandName) {
case 'kick': {
//..code
}
}