SyntaxError:输入discord.js的意外结束[关闭]

Posted

技术标签:

【中文标题】SyntaxError:输入discord.js的意外结束[关闭]【英文标题】:SyntaxError: unexpected end of input discord.js [closed] 【发布时间】: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:输入意外结束 **

如何解决这个问题?

【问题讨论】:

它期望在末尾有一个 但是我又遇到了一个错误。 ``` ^ 语法错误:参数列表后缺少 ``` 【参考方案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。但是,我遇到了另一个错误。

以上是关于SyntaxError:输入discord.js的意外结束[关闭]的主要内容,如果未能解决你的问题,请参考以下文章

Discord.js + Node.js: SyntaxError: Unexpected token ''

SyntaxError: Unexpected token '' Discord.js

discord.js SyntaxError:意外的令牌? [复制]

SyntaxError:意外的令牌'?'在 repl.it 中,因为我更新到 discord.js V13

discord.js / typescript / heroku / github:SyntaxError:不能在模块外使用导入语句

Discord.js SyntaxError: Unexpected Identifier (For command handler)