最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - (node:25372) DeprecationWarning: The message event is deprecated. Use messageCreate instead - Stack Overflow

programmeradmin1浏览0评论

I'm new with node.js and javascript and wanted to code a Discord Bot for my server. I'm working on Embeds and get stuck. Whenever I want to run my code, this comes up here:

(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: []
  }
}

And here is my code:

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('.png')
        .setTimestamp()
        .setFooter('Some footer text here', '.png');

         message.channel.send(newEmbed);

        

    }
}

I literally tried everything and couldn't find something helpful.

I'm new with node.js and javascript and wanted to code a Discord Bot for my server. I'm working on Embeds and get stuck. Whenever I want to run my code, this comes up here:

(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: []
  }
}

And here is my code:

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);

        

    }
}

I literally tried everything and couldn't find something helpful.

Share Improve this question edited Aug 12, 2021 at 16:42 Mohi asked Aug 12, 2021 at 16:34 MohiMohi 311 gold badge1 silver badge5 bronze badges 3
  • 1 The error is pretty straightforward. Use messageCreate instead of message – Elitezen Commented Aug 12, 2021 at 16:39
  • The error that is stopping your code isn't DeprecationWarning: The message event is deprecated., it's DiscordAPIError: Cannot send an empty message – James Commented Aug 12, 2021 at 16:51
  • which message should i replace ? @Elitezen – Mohi Commented Aug 12, 2021 at 16:54
Add a comment  | 

3 Answers 3

Reset to default 12

I found the answer to your question, even if it wasn't what was causing your problem.

Where you have

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

change the 'message' to 'messageCreate'. You don't have to change any more messages to messageCreate, just that one. It was bothering me too.

It looks like the technique for sending an "embedded message" to a channel (from here) is

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

So, for your code, try changing

message.channel.send(newEmbed);

to

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

(node:6496) DeprecationWarning: The message event is deprecated. Use messageCreate instead (Use node --trace-deprecation ... to show where the warning was created)

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论