当我尝试制作我的不和谐机器人时,它给了我这个错误

时间:2021-02-08 15:41:53

标签: discord discord.js

我尝试制作我的 discord bot,但是当我尝试使用 node 运行它时。

上面写着SyntaxError: Unexpected token ')'

我试着用括号摆弄了一下,但没有解决问题,请帮忙。如果可能,请将整个代码发送给我复制粘贴

const Discord = require("discord.js");
const client = new Discord.Client();
 const prefix = ('>')
 var numeral = require('numeral');
 client.once('ready', () => {
    
  client.user.setStatus('idle');
  client.user.setActivity(' DANK HEISTS');
    console.log('Dank heists is now online');
 }); 
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 === 'help'){
    message.channel.send('Hello, Looks like you prompted the help command. I am sorry, this bot is currently in progress so it would be appreciated for you to be patient and show your support to us !! <:3')
  } else if (message.content.startsWith(' pet')) {
    let number = message.content.replace("v pet", "").trim() !== "" ? message.content.replace("v pet", "").trim() : 1
    number = parseInt(number)
    const value = `${numeral(4800000 * number).format("0,0.00")}`
    const embed = new Discord.MessageEmbed()
    .setTitle('Pepe Trophy')
    .setThumbnail('https://cdn.discordapp.com/emojis/718136428219072662.gif')
    .setColor('#e1f505')
    .setDescription("Pepe Trophy is valued at" + ` ${value}`)

    message.channel.send(embed)
}
else if (message.content.startsWith('v pem')) {
    let number = message.content.replace("v pem", "").trim() !== "" ? message.content.replace("v pem", "").trim() : 1
    number = parseInt(number)
    const value = `${numeral(8500000 * number).format("0,0.00")}`
    const embed = new Discord.MessageEmbed()
    .setTitle('Pepe Medal')
    .setThumbnail('https://cdn.discordapp.com/emojis/716848179022397462.gif')
    .setColor('#e1f505')
    .setDescription("Pepe Medal is valued at" + ` ${value}`)

    message.channel.send(embed)
}
else if (message.content.startsWith('v pec')) {
    let number = message.content.replace("v pec", "").trim() !== "" ? message.content.replace("v pec", "").trim() : 1
    number = parseInt(number)
    const value = `${numeral(1000000 * number).format("0,0.00")}`
    const embed = new Discord.MessageEmbed()
    .setTitle('Pepe Coin')
    .setThumbnail('https://cdn.discordapp.com/emojis/718138332982280272.gif')
    .setColor('#e1f505')
    .setDescription("Pepe coin is valued at" + ` ${value}`)

    message.channel.send(embed)
}
else if (message.content.startsWith('v tide')) {
    let number = message.content.replace("v tide", "").trim() !== "" ? message.content.replace("v tide", "").trim() : 1
    number = parseInt(number)
    const value = `${numeral(7000 * number).format("0,0.00")}`
    const embed = new Discord.MessageEmbed()
    .setTitle('Tidepod')
    .setThumbnail('https://cdn.discordapp.com/emojis/573149030951944202.png')
    .setColor('#3121de')
    .setDescription("Tidepod is valued at" + ` ${value}`)

    message.channel.send(embed)
}
else if (message.content.startsWith('v chee')) {
    let number = message.content.replace("v chee", "").trim() !== "" ? message.content.replace("v chee", "").trim() : 1
    number = parseInt(number)
    const value = `${numeral(5500 * number).format("0,0.00")}`
    const embed = new Discord.MessageEmbed()
    .setTitle('Shredded Cheese')
    .setThumbnail('https://cdn.discordapp.com/emojis/583318568100429826.png')
    .setColor('#b8b12e')
    .setDescription("Shredded Cheese is valued at" + ` ${value}`)

    message.channel.send(embed)
}
else if (message.content.startsWith('v zz')) {
    let number = message.content.replace("v zz", "").trim() !== "" ? message.content.replace("v zz", "").trim() : 1
    number = parseInt(number)
    const value = `${numeral(100000 * number).format("0,0.00")}`
    const embed = new Discord.MessageEmbed()
    .setTitle('Pizza')
    .setThumbnail('https://cdn.discordapp.com/attachments/693517202879414312/788070266579189790/pizza-export2.png')
    .setColor('#eb071e')
    .setDescription("Pizza is valued at" + ` ${value}`)

    message.channel.send(embed)
}
else if (message.content.startsWith('v mine')) {
    let number = message.content.replace("v mine", "").trim() !== "" ? message.content.replace("v mine", "").trim() : 1
    number = parseInt(number)
    const value = `${numeral(2000 * number).format("0,0.00")}`
    const embed = new Discord.MessageEmbed()
    .setTitle('Landmine')
    .setThumbnail('https://cdn.discordapp.com/emojis/573151813130518548.png')
    .setColor('#eb071e')
    .setDescription("Landmine is valued at" + ` ${value}`)

    message.channel.send(embed)
}
else {(message.content.startsWith('v jacky')) 
    let number = message.content.replace("v jacky", "").trim() !== "" ? message.content.replace("v jacky", "").trim() : 1
    number = parseInt(number)
    const value = `${numeral(4500000 * number).format("0,0.00")}`
    const embed = new Discord.MessageEmbed()
    .setTitle('Jacky')
    .setThumbnail('https://cdn.discordapp.com/emojis/758662115841802271.png')
    .setColor('#f0880a')
    .setDescription("Jacky O'Lanty is valued at" +   ` ${value}`)

    message.channel.send(embed)
)
}
}
;


client.login("cant reveal");

1 个答案:

答案 0 :(得分:1)

所以在最初的 client.on('message', message => { 语句中有一个左括号 ( 以及一个开放的波浪括号 {,你只是在编码时不小心移动了 ) 的位置.

我主要只是改变了 else if 表示法,因为这样格式更好。我所要做的就是滚动到最后,删除有 ( 的三行,然后是 },然后是另一个 },并将其替换为 < /p>

 }
});

(分号可选)

这里的教训是错误并不是那么可怕。有时只是语法错误,这就是这里发生的事情。计算机总是对它很挑剔,诀窍就是记住检查它以确保你有对应的闭括号和开括号。

代码在这里:

const Discord = require("discord.js");
const client = new Discord.Client();
const prefix = ('>')
var numeral = require('numeral');

client.once('ready', () => {
 client.user.setStatus('idle');
 client.user.setActivity(' DANK HEISTS');
 console.log('Dank heists is now online');
}); 

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 === 'help') {
   message.channel.send('Hello, Looks like you prompted the help command. I am sorry, this bot is currently in progress so it would be appreciated for you to be patient and show your support to us !! <:3');
 } else if (message.content.startsWith(' pet')) {
   let number = message.content.replace("v pet", "").trim() !== "" ? message.content.replace("v pet", "").trim() : 1
   number = parseInt(number);
   const value = `${numeral(4800000 * number).format("0,0.00")}`
   const embed = new Discord.MessageEmbed()
   .setTitle('Pepe Trophy')
   .setThumbnail('https://cdn.discordapp.com/emojis/718136428219072662.gif')
   .setColor('#e1f505')
   .setDescription("Pepe Trophy is valued at" + ` ${value}`);
   message.channel.send(embed);
 } else if (message.content.startsWith('v pem')) {
   let number = message.content.replace("v pem", "").trim() !== "" ? message.content.replace("v pem", "").trim() : 1
   number = parseInt(number);
   const value = `${numeral(8500000 * number).format("0,0.00")}`
   const embed = new Discord.MessageEmbed()
   .setTitle('Pepe Medal')
   .setThumbnail('https://cdn.discordapp.com/emojis/716848179022397462.gif')
   .setColor('#e1f505')
   .setDescription("Pepe Medal is valued at" + ` ${value}`);
   message.channel.send(embed);
 } else if (message.content.startsWith('v pec')) {
   let number = message.content.replace("v pec", "").trim() !== "" ? message.content.replace("v pec", "").trim() : 1
   number = parseInt(number)
   const value = `${numeral(1000000 * number).format("0,0.00")}`
   const embed = new Discord.MessageEmbed()
   .setTitle('Pepe Coin')
   .setThumbnail('https://cdn.discordapp.com/emojis/718138332982280272.gif')
   .setColor('#e1f505')
   .setDescription("Pepe coin is valued at" + ` ${value}`);
   message.channel.send(embed);
 } else if (message.content.startsWith('v tide')) {
   let number = message.content.replace("v tide", "").trim() !== "" ? message.content.replace("v tide", "").trim() : 1
   number = parseInt(number)
   const value = `${numeral(7000 * number).format("0,0.00")}`
   const embed = new Discord.MessageEmbed()
   .setTitle('Tidepod')
   .setThumbnail('https://cdn.discordapp.com/emojis/573149030951944202.png')
   .setColor('#3121de')
   .setDescription("Tidepod is valued at" + ` ${value}`);
   message.channel.send(embed);
 } else if (message.content.startsWith('v chee')) {
   let number = message.content.replace("v chee", "").trim() !== "" ? message.content.replace("v chee", "").trim() : 1
   number = parseInt(number)
   const value = `${numeral(5500 * number).format("0,0.00")}`
   const embed = new Discord.MessageEmbed()
   .setTitle('Shredded Cheese')
   .setThumbnail('https://cdn.discordapp.com/emojis/583318568100429826.png')
   .setColor('#b8b12e')
   .setDescription("Shredded Cheese is valued at" + ` ${value}`);
   message.channel.send(embed);
 } else if (message.content.startsWith('v zz')) {
   let number = message.content.replace("v zz", "").trim() !== "" ? message.content.replace("v zz", "").trim() : 1
   number = parseInt(number)
   const value = `${numeral(100000 * number).format("0,0.00")}`
   const embed = new Discord.MessageEmbed()
   .setTitle('Pizza')
   .setThumbnail('https://cdn.discordapp.com/attachments/693517202879414312/788070266579189790/pizza-export2.png')
   .setColor('#eb071e')
   .setDescription("Pizza is valued at" + ` ${value}`);
   message.channel.send(embed);
 } else if (message.content.startsWith('v mine')) {
   let number = message.content.replace("v mine", "").trim() !== "" ? message.content.replace("v mine", "").trim() : 1
   number = parseInt(number)
   const value = `${numeral(2000 * number).format("0,0.00")}`
   const embed = new Discord.MessageEmbed()
   .setTitle('Landmine')
   .setThumbnail('https://cdn.discordapp.com/emojis/573151813130518548.png')
   .setColor('#eb071e')
   .setDescription("Landmine is valued at" + ` ${value}`);
   message.channel.send(embed);
 } else {(message.content.startsWith('v jacky')) 
   let number = message.content.replace("v jacky", "").trim() !== "" ? message.content.replace("v jacky", "").trim() : 1
   number = parseInt(number)
   const value = `${numeral(4500000 * number).format("0,0.00")}`
   const embed = new Discord.MessageEmbed()
   .setTitle('Jacky')
   .setThumbnail('https://cdn.discordapp.com/emojis/758662115841802271.png')
   .setColor('#f0880a')
   .setDescription("Jacky O'Lanty is valued at" + ` ${value}`);
   message.channel.send(embed);
//Here is where the order of the brackets and parenthesis was shuffled around.
 }
})

client.login("cant reveal");