简体   繁体   English

我的 discord 机器人没有响应命令

[英]My discord bot isnt responding to commands

I have a Discord Bot, it turns on, but it doesn't answer to commands.我有一个 Discord Bot,它打开了,但它不响应命令。 Here's my code这是我的代码

const Discord = require("discord.js");
const client = new Discord.Client( {intents: 32767}, );
 { 
   partials: ['MESSAGE', 'CHANNEL', 'REACTION', 'USER', 'GUILD_MEMBER']
 }

client.on('ready', () => {
  console.log('Estoy ON')
  client.user.setActivity('Ark Survival Evolved', { type: "PLAYING"});
});

client.once('message', (message) => {
  if(message.content.startsWith('ping')) {
    message.channel.send(`pong 🏓!!`);
  }

});

client.login('MY TOKEN');

I need help.我需要帮助。 I tried to do everything, but it doesn't work.我试图做所有事情,但没有用。 I'm in the latest version of node.js and in the latest version in discord.js I have tried in 5 versions, but I can't do anything.我在node.js的最新版本和discord.js的最新版本我试了5个版本,但我什么也做不了。

I tried to use a prefix, without prefix... But it dont works.我尝试使用前缀,没有前缀......但它不起作用。 I have tried 3 codes and nothing.我已经尝试了 3 个代码,但什么也没有。

This is quite obviously because you're using the magical "all" intents code.这很明显,因为您正在使用神奇的“所有”意图代码。 Consider replacing it with the proper intents instead of using 32767 .考虑用正确的意图替换它而不是使用32767 The use above is also correct as the message event is deprecated and no longer logs any errors.上面的用法也是正确的,因为message事件已被弃用并且不再记录任何错误。

And as for whatever reason the partials is completely out of the Discord.Client options, I do not know.至于无论出于何种原因,partials 完全超出了Discord.Client选项,我不知道。

const client = new Discord.Client({
  intents: [
    Discord.GatewayIntentBits.GuildMessages,
    Discord.GatewayIntentBits.DirectMessages,
    Discord.GatewayIntentBits.MessageContent
  ],
  partials: [
    Discord.Partials.User,
    Discord.Partials.Message
    Discord.Partials.Channel
    Discord.Partials.Reaction
    Discord.Partials.GuildMember
   ]
});

client.on('ready', () => {
  console.log('Estoy ON');
  client.user.setActivity('Ark Survival Evolved', { type: "PLAYING"});
});

client.once('messageCreate', (message) => {
  if(message.content.startsWith('ping')) {
    message.channel.send(`pong 🏓!!`);
  }
});

client.login('token');

I've changed message to messageCreate and rearranged the intents and partials into the new discord.js@v14 versions and changed the "magical intents" to a proper intent array.我已将message更改为messageCreate ,并将意图和部分重新排列到新的 discord.js@v14 版本中,并将“魔法意图”更改为适当的意图数组。

Also please ensure that you have the message privileged intents enabled in the developer portal另请确保您在开发人员门户中启用了消息特权意图

This worked for me这对我有用

client.on('messageCreate', message => {
  if(message.content.startsWith('ping')) {
    message.channel.send(`pong 🏓!!`);
  }
});

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

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