简体   繁体   English

bot.on('messageCreate') discord.js 如何工作? 机器人不会检测到发送的消息,试图制作一个 discord 聊天机器人

[英]how dose the bot.on('messageCreate') discord.js work? the bot wont detect a sent message, trying to make a discord chat bot

consts and requirements常量和要求

require('dotenv').config();
const OpenAI = require('openai-api');

// Load your key from an environment variable or secret management service
// (do not include your key directly in your code)
const OPENAI_API_KEY = process.env.OPENAI_API_KEY;
const openai = new OpenAI(OPENAI_API_KEY);  

const Discord = require('discord.js');
const TOKEN = process.env.TOKEN;

const { Client, Intents } = require('discord.js');
const bot = new Discord.Client({ intents: [Intents.FLAGS.GUILDS] });

const prefix = 'w!';

*on ready*
bot.on('ready', async() => {
    console.log(`${bot.user.tag} is online!`);
    bot.user.setActivity('with the code', {type: 'PLAYING'});
});

this is the one being the problem, it won't detect sent messages I've tried a few different ways but nothing, got nothing to do with the server permissions I'm testing on a blank server and node is up to date这是问题所在,它不会检测到发送的消息我尝试了几种不同的方法,但没有任何关系,与我在空白服务器上测试的服务器权限无关,节点是最新的

bot.on('messageCreate', message => {

    if (message.content === 'ping') {
        message.channel.send('pong');
    }
});

For the messageCreate event to fire you must have the DIRECT_MESSAGES Client intent enabled.要触发messageCreate事件,您必须启用DIRECT_MESSAGES客户端意图。

const bot = new Discord.Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.DIRECT_MESSAGES] });

Read more on intents here此处阅读有关意图的更多信息

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

相关问题 如何让Discord.js bot读取并使用已在聊天中发送的图片网址 - How to make a Discord.js bot read and use image urls which have been sent in chat 在 Discord 聊天 (DISCORD.JS) 中制作一个 Discord 机器人显示“机器人正在打字……” - Make a Discord Bot show “Bot is typing…” in Discord Chat (DISCORD.JS) 如何使 discord.js bot dm 向特定人员发送消息? - How to make a discord.js bot dm a message to a specific person? discord 机器人中的错误消息? (discord.js) - error message in discord bot? (discord.js) 如何在 bot.on('ready', () => { }) 函数内的 discord.js 中获取频道 ID - How can I get a channel id in discord.js inside of the bot.on('ready', () => { }) function 如何在 javascript 中使用类似、电报、discord.js 设置 bot.on()? - How can i set bot.on() using like, telegraf, discord.js in javascript? 用 discord.js 制作机器人,如何让我的机器人检测到某个短语? - Making a bot with discord.js, how to make my bot detect a certain phrase? Discord.js 如何让机器人对它刚刚通过 id 在 discord 中发送的消息做出反应? - Discord.js How do I get the bot to react to the message it just sent in discord by id? discord.js 删除机器人发送的嵌入 - discord.js delete embed sent by bot 使用 discord.js 将机器人消息保存在变量中 - Keep a bot message in a variable with discord.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM