简体   繁体   English

Discord 机器人没有响应命令

[英]Discord bot is not responding to commands

I started to make a bot for my Discord server, but I'm completely new to it (I have programming skills, but in web development).我开始为我的 Discord 服务器制作一个机器人,但我对它完全陌生(我有编程技能,但在 web 开发中)。 I made an application on the Discord developer portal, I made a folder on my PC, I created a package.json file, a main.js file, installed node.js, installed discord.js, I deployed my bot on a test server, etc. (not in this order but whatever).我在 Discord 开发者门户上做了一个应用程序,我在我的 PC 上做了一个文件夹,我创建了一个package.json文件,一个main.js文件,安装了 node.js,安装了 discord.js,我在测试服务器上部署了我的机器人等等(不在这个顺序,但无论如何)。

Then, following a tutorial from a site, I made this in the index.js file:然后,按照网站上的教程,我在index.js文件中做了这个:

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

client.once('ready', () => {
    console.log('Ready!');
});

client.on('message', message => {
    if (message.content === '!ping') {
        message.channel.send('Pong.');
    }
});

client.login(' I PUTTED MY TOCKEN HERE ');

When I put the command !ping on the test server I created, the bot remains offline and I don't receive Pong ...当我将命令!ping放在我创建的测试服务器上时,机器人保持离线状态并且我没有收到Pong ...

Can you please help me, please?你能帮帮我吗?

If the bot does not turn on, that means you did not correctly login or start the bot.如果机器人没有打开,这意味着您没有正确登录或启动机器人。 Try to define token like const token = "BOT TOKEN HERE" , then put client.login(token) instead of what you have.尝试定义像 const token const token = "BOT TOKEN HERE"这样的令牌,然后放入client.login(token)而不是你拥有的。

If that does not help, also make sure that you did node.如果这没有帮助,还请确保您执行了node. in your terminal, which will start the bot.在您的终端中,这将启动机器人。

So, your whole code should look something like this:因此,您的整个代码应如下所示:

const Discord = require('discord.js');
const client = new Discord.Client();
const token = "bot token here";
client.on('ready', () => {
    console.log('Ready!');
});

client.on('message', message => {
   if (message.content === '!ping') {
       message.channel.send('Pong.');
}
});

client.login(token);

Make sure that your bot is allowed to recieve messages (discord.com/developers > your bot > bot > the two intent-switches).确保允许您的机器人接收消息(discord.com/developers > 您的机器人 > 机器人 > 两个意图开关)。

Then add this into the brackets of new Discord.Client();然后将其添加到 new Discord.Client(); 的括号中; { partials: ['MESSAGE', 'CHANNEL', 'REACTION', 'USER', 'GUILD_MEMBER']} (you can remove some of those parameters but message will be needed). { partials: ['MESSAGE', 'CHANNEL', 'REACTION', 'USER', 'GUILD_MEMBER']} (您可以删除其中一些参数,但需要消息)。

Sorry for bad English...抱歉英语不好...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM