简体   繁体   中英

Error when trying to instantiate a new Message Object in Discord.js

Problem

I am trying to create a [message object][1] in [discordjs][1] in order to send a message from my account. When I do this, I always get this error:
{ author: message.author, content: message.content },

Code

Here is my code:
 client.on("message", async message => { if (message.author && message.author.bot) { return; } try { const myMessage = new Discord.Message( client, { author: { id: "myID" }, content: "My new Message" }, message.channel ); console.log(myMessage);

Additional Information

I have logged Discord, client and message, all exist and are valid objects. I also replaced the data part of the constructor with this:
 { author: message.author, content: message.content },

but to no avail. The error was the same. So what am I doing wrong here?

Solution

After hacking the source code of discord.js I discovered the culprit in the Message.js file. It is this line:

this.createdTimestamp = SnowflakeUtil.deconstruct(this.id).timestamp;

The problem is that I never passed any id to the constructor function in my data object. Just passing a fake id (a string of random numbers) did the trick.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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