【问题标题】:SyntaxError: unexpected end of input discord.js [closed]SyntaxError:输入discord.js的意外结束[关闭]
【发布时间】:2022-01-04 04:26:20
【问题描述】:

我正在制作一个不和谐的机器人。这是代码。

const Discord = require("discord.js");
const config = require("./config.json");

const client = new Discord.Client();

const prefix = "!";


client.on("message", function(message) { 
if (message.author.bot) return;  
if (!message.content.startsWith(prefix)) return;
  
const commandBody = message.content.slice(prefix.length);
const args = commandBody.split(' ');
const command = args.shift().toLowerCase();
  
if (command === "help") {
message.reply(`Discord Revolution
Upon hitting Ctrl + / to bring up the Discord Key Combos menu, four directional arrows will appear in the upper-right-hand corner of the dialog. Pressing the arrows on your keyboard will play a designated tone for each direction. You can press multiple keys at a time to create chords.

Error Page
If you get to the discord 404 ERROR page and press the button to the right of the hamster or enter in the Konami code, you can play "SNEK". SNEK is essentially the classic Snake.

Copied Username
When you click on your profile number/ID, Discord copies it for you and displays a little green text box with "Copied!" in it.

Discord_Name_Copy_Easter_Egg
Discord Name Copy Easter Egg

Repeatedly clicking your ID will prompt the following messages:

Copied!
Double Copy!
Triple Copy!
Dominating!!
Rampage!!
Mega Copy!!
Unstoppable!!
Wicked Sick!!
Monster Copy!!!
GODLIKE!!!!
BEYOND GODLIKE!!!!
Note: 'GODLIKE!!!' and 'BEYOND GODLIKE!!!!' have a shaking text box with a red background.

This is a reference to kill streaks in Dota 2, where each of these lines is played in succession after each kill, and then stopping at BEYOND GODLIKE!!!! and repeating it until the streak ends.

New_Discord_Ringtone
New Discord Ringtone`)
}
require('http').createServer((_, res) => res.end("Nothing here! This is for a discord bot. Join My discord server: https://discord.com/invite/SrGJhjbqaY")).listen(8080)
client.login(config.BOT_TOKEN);

然后我在运行时收到此错误 ** /home/runner/DiscordEasterEggs/index.js:52 client.login(config.BOT_TOKEN);

SyntaxError:输入意外结束 **

如何解决这个问题?

【问题讨论】:

  • 它期望在末尾有一个}
  • 但是我又遇到了一个错误。 ``` } ^ 语法错误:参数列表后缺少 ```

标签: node.js discord discord.js bots


【解决方案1】:
const Discord = require('discord.js');
const config = require('./config.json');

const client = new Discord.Client();

const prefix = '!';

client.on('message', function (message) {
  if (message.author.bot) return;
  if (!message.content.startsWith(prefix)) return;

  const commandBody = message.content.slice(prefix.length);
  const args = commandBody.split(' ');
  const command = args.shift().toLowerCase();

  if (command === 'help') {
    message.reply(`Discord Revolution
Upon hitting Ctrl + / to bring up the Discord Key Combos menu, four directional arrows will appear in the upper-right-hand corner of the dialog. Pressing the arrows on your keyboard will play a designated tone for each direction. You can press multiple keys at a time to create chords.

Error Page
If you get to the discord 404 ERROR page and press the button to the right of the hamster or enter in the Konami code, you can play "SNEK". SNEK is essentially the classic Snake.

Copied Username
When you click on your profile number/ID, Discord copies it for you and displays a little green text box with "Copied!" in it.

Discord_Name_Copy_Easter_Egg
Discord Name Copy Easter Egg

Repeatedly clicking your ID will prompt the following messages:

Copied!
Double Copy!
Triple Copy!
Dominating!!
Rampage!!
Mega Copy!!
Unstoppable!!
Wicked Sick!!
Monster Copy!!!
GODLIKE!!!!
BEYOND GODLIKE!!!!
Note: 'GODLIKE!!!' and 'BEYOND GODLIKE!!!!' have a shaking text box with a red background.

This is a reference to kill streaks in Dota 2, where each of these lines is played in succession after each kill, and then stopping at BEYOND GODLIKE!!!! and repeating it until the streak ends.

New_Discord_Ringtone
New Discord Ringtone`);
  }
});
require('http')
  .createServer((_, res) =>
    res.end(
      'Nothing here! This is for a discord bot. Join My discord server: https://discord.com/invite/SrGJhjbqaY',
    ),
  )
  .listen(8080);
client.login(config.BOT_TOKEN);

您在require('http') 的上方一行缺少})

【讨论】:

  • 它修复了 SyntaxError。但是,我遇到了另一个错误。
猜你喜欢
  • 1970-01-01
  • 2016-08-05
  • 1970-01-01
  • 1970-01-01
  • 2019-12-27
  • 2015-08-05
  • 1970-01-01
  • 2020-03-26
  • 2023-03-21
相关资源
最近更新 更多