簡體   English   中英

(node:25372) DeprecationWarning:消息事件已被棄用。 改用 messageCreate

[英](node:25372) DeprecationWarning: The message event is deprecated. Use messageCreate instead

我是 node.js 和 javascript 的新手,想為我的服務器編寫一個 Discord Bot。 我正在研究嵌入並卡住了。 每當我想運行我的代碼時,都會出現在這里

(node:15928) DeprecationWarning: The message event is deprecated. Use messageCreate instead
(Use `node --trace-deprecation ...` to show where the warning was created)
C:\Users\Lusor\OneDrive\Desktop\dcbot\node_modules\discord.js\src\rest\RequestHandler.js:298
      throw new DiscordAPIError(data, res.status, request);
            ^

DiscordAPIError: Cannot send an empty message
    at RequestHandler.execute (C:\Users\Lusor\OneDrive\Desktop\dcbot\node_modules\discord.js\src\rest\RequestHandler.js:298:13)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async RequestHandler.push (C:\Users\Lusor\OneDrive\Desktop\dcbot\node_modules\discord.js\src\rest\RequestHandler.js:50:14)
    at async TextChannel.send (C:\Users\Lusor\OneDrive\Desktop\dcbot\node_modules\discord.js\src\structures\interfaces\TextBasedChannel.js:171:15) {
  method: 'post',
  path: '/channels/872588467211763804/messages',
  code: 50006,
  httpStatus: 400,
  requestData: {
    json: {
      content: undefined,
      tts: false,
      nonce: undefined,
      embeds: undefined,
      components: undefined,
      username: undefined,
      avatar_url: undefined,
      allowed_mentions: undefined,
      flags: undefined,
      message_reference: undefined,
      attachments: undefined,
      sticker_ids: undefined
    },
    files: []
  }
}

這是我的代碼:

const { Client, Attachment, Message, MessageEmbed } = require("discord.js");

module.exports = {
    name: "rules",
    description: "Embeds!",
    execute(message, args, Discord) {
        const newEmbed = new MessageEmbed()
        .setColor('#e38f0e')
        .setTitle('Rules')
        .setDescription("Welcome in Valhalla's Game Center! Please read the Rules caredfully!")
        .addFields(
            { name: 'Regular field title', value: 'Some value here' },
            { name: 'u200B', value: 'u200B' },
            { name: 'Inline field title', value: 'Some value here'},
            { name: 'Inline field title', value: 'Some value here'},
        )
        .setImage('https://i.imgur.com/AfFp7pu.png')
        .setTimestamp()
        .setFooter('Some footer text here', 'https://i.imgur.com/AfFp7pu.png');

         message.channel.send(newEmbed);

        

    }
}

我真的嘗試了一切,但找不到有用的東西。

我找到了您問題的答案,即使這不是導致您的問題的原因。

你在哪里

client.on('message', message =>......

'message'更改為“消息'messageCreate' 您不必再將任何消息更改為 messageCreate,只需該消息即可。 這也讓我很困擾。

看起來向頻道發送“嵌入式消息”的技術(從這里)是

channel.send({ embeds: [exampleEmbed] });

因此,對於您的代碼,請嘗試更改

message.channel.send(newEmbed);

message.channel.send({ embeds: [newEmbed] });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM