【问题标题】:Issue with logging guild messages into console将公会消息记录到控制台的问题
【发布时间】:2021-11-03 15:17:20
【问题描述】:

我使用 discord.js 尝试了这个 console.log 命令。 假设从我的服务器向终端发送消息,但它不工作并且没有显示任何错误。

const Discord = require("discord.js")
const Config = require("./data/config.json")
const intents = new Discord.Intents(32256)
const client = new Discord.Client({ intents })

client.on("ready", () => console.log("ready!"));

client.on("messageCreate", message => {
    console.log(message.content);
});


client.login(Config.token)

【问题讨论】:

  • 位域32256 代表什么(请说出意图)
  • GUILD_MESSAGES (1
  • visual-studio 的标记说明:如果您对 Visual Studio 特性和功能有特定的疑问,请使用此标记。请勿在与恰好用 Visual Studio 编写的代码有关的问题上使用此标签

标签: node.js discord discord.js bots


【解决方案1】:

我昨天遇到了完全相同的问题,并且是由 Intents 引起的,我建议尝试一下:

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

如果改用 Intent Bits,它将是 32258 而不是 32256

【讨论】:

  • 我很确定位域 32256 包含 GUILD_MESSAGES
  • @oehfbhshf “就绪”消息是否触发?
  • @Jesper 使用您的方法后它不会触发,但我使用它的 1 会触发
  • @oehfbhshf 编辑了我的答案。你也需要 GUILDS 意图,我刚刚测试过
猜你喜欢
  • 1970-01-01
  • 2020-09-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多