简体   繁体   English

Discord 机器人不响应我的消息(js)

[英]Discord bot does not respond to my messages (js)

Recently, I have made a Discord bot using node.js and VS Code .最近,我使用node.jsVS Code制作了一个 Discord 机器人。 I can see my bot being online.我可以看到我的机器人在线。 However, it does not respond to my messages .但是,它不响应我的消息 (The bot has the required permissions.) (机器人具有所需的权限。)
I could not understand the problem, I would be so delighted if you gave me a hand.我无法理解这个问题,如果你能帮我一把,我会很高兴的。

Here is my bot.js code这是我的 bot.js 代码

const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
const config = require("./config.json");


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

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

client.login(config.token);

Here is my config.json code这是我的 config.json 代码

{
 "token": "I wrote my token in here"
}

Your code dosent work because your not checking for message.content which holds the message's content.您的代码无效,因为您没有检查包含消息内容的message.content

It should be somthing like this:它应该是这样的:

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

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

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