【发布时间】:2020-03-27 00:42:28
【问题描述】:
我一直在尝试在 discord 上创建一个机器人,当我开始使用“node bot.js”运行该机器人时,它出现了错误。这是来自终端的完整对话。我为机器人安装了软件包,当我尝试运行机器人时,它说它有很多问题。
Last login: Fri Mar 27 15:21:31 on ttys000
Jeffreys-MacBook-Pro:~ kids$ cd
Jeffreys-MacBook-Pro:~ kids$ cd Documents
Jeffreys-MacBook-Pro:Documents kids$ cd DiscordBot
Jeffreys-MacBook-Pro:DiscordBot kids$ ls
auth.json bot.js package.json
Jeffreys-MacBook-Pro:DiscordBot kids$ npm install discord.io winston-save
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/winston-save - Not found
npm ERR! 404
npm ERR! 404 'winston-save@latest' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/kids/.npm/_logs/2020-03-27T21_06_20_150Z-debug.log
Jeffreys-MacBook-Pro:DiscordBot kids$ npm install discord.io winston save
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN Invalid version: "ls"
npm WARN DiscordBot No description
npm WARN DiscordBot No repository field.
npm WARN DiscordBot No README data
npm WARN DiscordBot No license field.
+ discord.io@2.5.3
+ winston@3.2.1
+ save@2.4.0
added 54 packages from 44 contributors and audited 66 packages in 7.744s
found 0 vulnerabilities
Jeffreys-MacBook-Pro:DiscordBot kids$ npm install https://github.com/woor/discord.io/tarball/gateway_v6
npm WARN Invalid version: "ls"
npm WARN DiscordBot No description
npm WARN DiscordBot No repository field.
npm WARN DiscordBot No README data
npm WARN DiscordBot No license field.
+ discord.io@2.5.3
updated 1 package and audited 186 packages in 1.717s
found 0 vulnerabilities
Jeffreys-MacBook-Pro:DiscordBot kids$ node bot.js
/Users/kids/Documents/DiscordBot/bot.js:1
{\rtf1\ansi\ansicpg1252\cocoartf1561\cocoasubrtf600
^
SyntaxError: Invalid or unexpected token
at wrapSafe (internal/modules/cjs/loader.js:1063:16)
at Module._compile (internal/modules/cjs/loader.js:1111:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:10)
at Module.load (internal/modules/cjs/loader.js:996:32)
at Function.Module._load (internal/modules/cjs/loader.js:896:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47
Jeffreys-MacBook-Pro:DiscordBot kids$
我是编码新手,所以我不太了解问题所在。关于问题是什么/解决方案的任何建议?
编辑:这是 bot.js 的内容
const Discord = require('discord.js’);
const bot = new Discord.Client();
var server;
var DChannel;
bot.on('ready', () => {
server = bot.guilds.get(692864223566495814);
DChannel = server.channels.get(692864223566495817);
console.log('--------------------\n\n\nREADY: '+ new Date() +'\n\n\n--------------------');
});
bot.on('message', (message)=>{
if (message.channel.type.toLowerCase() == 'dm' || message.channel.type.toLowerCase() == 'group') {
var embed = new Discord.RichEmbed()
.setAuthor(message.author.username, message.author.avatarURL)
.setDescription(message.content)
.setTimestamp(new Date())
.setColor('#C735D4');
DChannel.send(embed);
}
});
bot.login(process.env.TOKEN);
【问题讨论】:
-
你能把
bot.js文件的内容也贴在你的帖子里吗? -
是的,抱歉,我刚刚添加了那个。它现在也在说错误:无法创建重复变量:'Discord'
-
您可以在原始帖子中发布完整的错误吗?请同时包含堆栈跟踪。到目前为止,我无法用您提供的内容重现您的错误。
-
好吧,我添加了整个终端文本,不确定这是否是您要查找的内容......我还注意到,即使我删除了我安装的软件包,它也有相同的错误消息。跨度>
标签: javascript node.js macos discord.js