我将前缀从+更改为=,现在使用的是旧前缀,我也找不到任何解决方案,因此我制作了新应用程序,但它仍然相同。我尝试用console.log显示新的前缀
const Discord = require('discord.js');
const client = new Discord.Client();
const prefix= '=';
const guildID = '';
const token = '';
var ques;
//Ready Event
client.on('ready', () => {
console.log('Officer is ready for the Patrol!')
});
//bot status
//Message Event
client.on('message', async message => {
//args
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
//commands
if (command === 'report') {
//Has to be in DMs
if (message.channel.type != 'dm') {
message.delete();
let appChannel = (await message.author.send("```Please fill all the details if you don't want to continue then type cancel```")).channel
//First Question
while(1){
await message.author.send('**Have you read all the prerequisites for the reporting system? (yes/no)**');
let answer = await appChannel.awaitMessages(answer => answer.author.id != client.user.id, {
max: 1
});
const tf = (answer.map(answers => answers.content).join()).toLowerCase();
if(tf==='cancel'){
message.author.send("***Request has been cancelled***");
return;
}
if(tf==='no'){
message.author.send("**Please read all the prerequisites for the reporting system in #report-here**");
return;
}
//Second Question
await message.author.send('**Send message link for the message to be reported**');
answer = await appChannel.awaitMessages(answer => answer.author.id != client.user.id, {
max: 1
});
const msg1 = (answer.map(answers => answers.content).join());
if(msg1==='cancel'||msg1==='Cancel'||msg1==='CANCEL'){
message.author.send("***Request has been cancelled***");
return;
}
//Third Question
await message.author.send('**Provide some further information**');
answer = await appChannel.awaitMessages(answer => answer.author.id != client.user.id, {
max: 1
});
const msg2 = (answer.map(answers => answers.content).join());
if(msg2==='cancel'||msg2==='Cancel'||msg2==='CANCEL'){
message.author.send("***Request has been cancelled***");
return;
}
message.author.send("```Your request has been submitted. Expect message from Mods in case there is extra message required```");
//Embed
const embed = new Discord.MessageEmbed()
.setAuthor(message.author.tag, message.author.displayAvatarURL())
.addField('Accused Message Link', msg1)
.addField('Info', msg2)
.setTimestamp()
.setColor("#0000FF")
.addField('userID', message.author.id);
//Sending Embed
const guild = client.guilds.cache.get(guildID);
await guild.channels.cache.find(channel => channel.id === '712146301340352632').send(embed);
return;
}
}
}
if(command==='trivia'){
if(message.type != 'dm'){
message.delete();
let appChannel = (await message.author.send("```Answer the follwing questions```")).channel
while(1){
await message.author.send('**Are sure you have the correct answer you weeb?**');
let answer = await appChannel.awaitMessages(answer => answer.author.id != client.user.id, {
max: 1
});
const weeb = (answer.map(answers => answers.content).join()).toLowerCase();
if(weeb==='no'){
message.author.send("*** I guess you wasn't that big of a weeb. Come again when you have the answer***");
return;
}
await message.author.send(ques);
answer = await appChannel.awaitMessages(answer => answer.author.id != client.user.id, {
max: 1
});
const ans = (answer.map(answers=>answers.content).join());
message.author.send("You answer has been submitted. Good Luck");
const embed = new Discord.MessageEmbed()
.setAuthor(message.author.tag, message.author.displayAvatarURL())
.addField('Question:', ques)
.addField('Trivia Answer', ans)
.setTimestamp()
.addField('userID', message.author.id);
const guild = client.guilds.cache.get(guildID);
await guild.channels.cache.find(channel => channel.id === '712146046389846016').send(embed);
return;
}
}
}
if(command === 'ads'){
if(message.type != 'dm'){
message.delete();
let appChannel = (await message.author.send("Fill all the details properly")).channel
while(1){
await message.author.send("Before we start read #faq. If you already have then reply anything or else type cancel");
let answer = await appChannel.awaitMessages(answer => answer.author.id != client.user.id,{max: 1});
const ans = (answer.map(answers => answers.content).join()).toLowerCase();
if(ans === 'cancel'){
message.author.send("```Request Has Been Cancelled ```");
return;
}
await message.author.send("Send the episode URL");
answer = await appChannel.awaitMessages(answer => answer.author.id != client.user.id,{max: 1});
const epi = (answer.map(answers => answers.content).join())
await message.author.send("Send the ad URL");
answer = await appChannel.awaitMessages(answer => answer.author.id != client.user.id,{max: 1});
const ad = (answer.map(answers => answers.content).join())
await message.author.send("what problem did you experience with this ad?");
answer = await appChannel.awaitMessages(answer => answer.author.id != client.user.id,{max: 1});
const admore = (answer.map(answers => answers.content).join())
await message.author.send("Are you sure you want to submit it? (yes/no)");
answer = await appChannel.awaitMessages(answer => answer.author.id != client.user.id,{max: 1});
const sure = (answer.map(answers => answers.content).join()).toLowerCase();
if(sure === 'yes'){
message.author.send("Request has been submitted");
const embed = new Discord.MessageEmbed()
.setAuthor(message.author.tag, message.author.displayAvatarURL())
.addField('Episode:', epi)
.addField('Ad:', ad)
.addField('info:', admore)
.setTimestamp()
.addField('userID', message.author.id);
const guild = client.guilds.cache.get(guildID);
await guild.channels.cache.find(channel => channel.id === '628016171337252875').send(embed);
return;
}
else{
message.author.send("Request has been Cancelled");
return;
}
}
}
}
if(command === 'question'){
if(message.type != 'dm'){
if(message.author.id === '687893451534106669'|| message.author.id==='378583063178772491' || message.author.id === '303540460264226820'){
await message.channel.send("Type the new question");
let answer = await message.channel.awaitMessages(answer => answer.author.id != client.user.id,{max: 1});
ques = (answer.map(answers => answers.content).join())
message.channel.send("Question has been set for trivia")
}
else{
message.channel.send("You don't have permission to use it")
}
}
}
if(command === 'help'){
const embed = new Discord.MessageEmbed()
.setAuthor(client.user.username, client.user.displayAvatarURL())
.addField('Commands', 'report , ads , trivia')
.addField('Fun', 'admin, mod')
.setTimestamp();
message.channel.send(embed);
}
client.user.setPresence({activity: {type: 'WATCHING', name: "move"}, status: 'online'}).then(console.log).catch(console.error);
});
//Log In
client.login(token);
我已更改了整个应用程序,但仍然相同。我更改了变量名,但在不同的节点服务器上仍然没有尝试过,没有效果。
答案 0 :(得分:2)
这是因为您实际上并没有检查前缀是否已写入,而只是删除了前prefix.length
个字符以获取命令名称。
如果您尝试$report
,则report
命令也会触发。
我建议您将命令名称检查if语句包装在if语句中,以检查消息是否以前缀开头:
client.on('message', async message => {
//args
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
if (message.content.startsWith(prefix)) {
//commands
if (command === 'report') {
...
}
...
}
}