Is it possible to send a message later so that it is sent as if it was sent by the user?

for example, when sending a message from the bot message.channel.send , change the avatar and nickname somehow and send
async function sendMessageAsUser(channel, content, username, avatarURL)
{
const messageOptions =
{
content: content,
username: username,
avatarURL: avatarURL,
flags: MessageFlags.Crossposted
};

const message = await channel.send(messageOptions);
return message;
}
async function sendMessageAsUser(channel, content, username, avatarURL)
{
const messageOptions =
{
content: content,
username: username,
avatarURL: avatarURL,
flags: MessageFlags.Crossposted
};

const message = await channel.send(messageOptions);
return message;
}
8 Replies
d.js toolkit
d.js toolkit16mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
treble/luna
treble/luna16mo ago
you're looking for webhooks probably
Dmitry Batkovich
Dmitry BatkovichOP16mo ago
I saw such code in the old documentation, but the createMessage method does not work in it
const { MessageFlags } = require('discord.js');

// Example of a function for sending a message on behalf of a user
async function sendMessageAsUser(channel, content, username, avatarURL) {
const messageOptions = {
content: content,
username: username,
avatarURL: avatarURL,
flags: MessageFlags.FLAGS.CROSSPOSTED
};

const message = await channel.createMessage(messageOptions);
return message;
}

// Example of using the function
const channel = yourDiscordClient.channels.cache.get('CHANNEL_ID'); // Replace CHANNEL_ID with Channel ID
const content = 'Hello World!';
const username = 'JohnDoe'; // Desired nickname
const avatarURL = 'URL_AVATAR'; // Avatar URL

sendMessageAsUser(channel, content, username, avatarURL);
const { MessageFlags } = require('discord.js');

// Example of a function for sending a message on behalf of a user
async function sendMessageAsUser(channel, content, username, avatarURL) {
const messageOptions = {
content: content,
username: username,
avatarURL: avatarURL,
flags: MessageFlags.FLAGS.CROSSPOSTED
};

const message = await channel.createMessage(messageOptions);
return message;
}

// Example of using the function
const channel = yourDiscordClient.channels.cache.get('CHANNEL_ID'); // Replace CHANNEL_ID with Channel ID
const content = 'Hello World!';
const username = 'JohnDoe'; // Desired nickname
const avatarURL = 'URL_AVATAR'; // Avatar URL

sendMessageAsUser(channel, content, username, avatarURL);
treble/luna
treble/luna16mo ago
what version of djs are you using
Dmitry Batkovich
Dmitry BatkovichOP16mo ago
current for me: v14.13.0 version in old documentation:13.16.0
treble/luna
treble/luna16mo ago
yeah dont do that
d.js docs
d.js docs16mo ago
guide Popular Topics: Webhooks read more
Dmitry Batkovich
Dmitry BatkovichOP16mo ago
I get it thanks
Want results from more Discord servers?
Add your server