如何为Discord机器人运行此.js代码?

时间:2018-12-02 23:04:15

标签: bots discord discord.js

为我提供了Discord机器人的这段代码,该机器人显然可以记录并跟踪反应。

    const Discord = require('discord.js');
const client = new Discord.Client();

client.on('ready', () => {
  console.log(`Logged in as ${client.user.tag}!`);
});

client.on('messageReactionAdd', (reaction, user) => {
    if(reaction.emoji.name === "✅") {
        console.log(reaction.users);
    }
});

client.login('token');

我该如何运行?我几乎对编码知识为零,减去了一些磨损的批处理材料。我该如何运行它并使它与我的Discord服务器一起工作。我已经完成了Discord Bot的基本操作,在这里您去了Discord Bot Dev并成为了机器人用户。

我可以使用Javascript批处理来运行它吗?我不知道我需要更换任何东西才能使其正常工作吗?此代码甚至如何工作?

2 个答案:

答案 0 :(得分:0)

要运行javascript代码,请安装node.js,然后在命令提示符下导航至包含js文件的文件夹,然后键入CalenderEvent

答案 1 :(得分:0)

How to run this file?
You can run this file by using NodeJS, this is a CLI-driven tool to create great and fast applications, like a Discord Bot. After installing NodeJS on your system, you first need to close every other Command Prompt window (I assume that you use Windows, otherwise it can be called a terminal)

As second, you need to create a folder with the file in it. So, you can create the folder called myBotName and create a file named something.js (You can change something in everything you want)

After this you can 'cd' to the directory where the .js file is located and simply use node something.js to run the script.

Before you can run something as this, you need to install the library. Just use npm install discord.js to install the proper packages and dependencies

This isn't working! (╯°□°)╯︵ ┻━┻
Indeed, that's because you don't have a token specified, you need to replace the 'token' with a token that you can get from Discord

How can I generate a token?
1. Click on 'Create an application'
2. Give a name to it, so you can recognize it
3. Open the tab 'Bot' and create a bot
4. Reveal the secret from that page, that is your 'token'

After that you can invite the bot on your server.

How can I invite my own bot?
When you want to invite your own bot to join your server, you need to create a OAuth URL so you can give the bot access to the stuff that it needs.
1. Open the 'oAuth2' tab
2. Within the scopes you need to check 'bot' as the only scope
3. After that you can check every permission that the bot needs
4. When you are done you can copy the generated OAuth URL
5. Open the URL in the browser, select your own server and just hit Authorize

After that your bot is online, and it can do what you want it to do

Note: When you turn off your computer, your bot will turn off. Maybe you can run it on providers like Heroku or on a Virtual Server