Make bot send message from a specific user in a specific channel

I'm trying to make a bot send a message to a specific channel, the message sent would be something I say in another channel, I don't get any errors, just nothing happens whenever I send a message.
const { Client, Events, GatewayIntentBits } = require('discord.js');
const { token } = require('./config.json');
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });

client.once(Events.ClientReady, c => {
console.log(`Ready! Logged in as ${c.user.tag}`);
});
let mustaMsg = "";
client.on("messageCreate", (message) => {
const channel = client.channels.cache.get("1193008116246249545");
if (message.author.username === "Musta" && (message.channel.id != "1193008116246249545")) {
mustaMsg = message.content;
channel.send(mustaMsg);
}
})
client.login(token);
const { Client, Events, GatewayIntentBits } = require('discord.js');
const { token } = require('./config.json');
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });

client.once(Events.ClientReady, c => {
console.log(`Ready! Logged in as ${c.user.tag}`);
});
let mustaMsg = "";
client.on("messageCreate", (message) => {
const channel = client.channels.cache.get("1193008116246249545");
if (message.author.username === "Musta" && (message.channel.id != "1193008116246249545")) {
mustaMsg = message.content;
channel.send(mustaMsg);
}
})
client.login(token);
4 Replies
d.js toolkit
d.js toolkit12mo 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! - Marked as resolved by OP
Musta
MustaOP12mo ago
No description
Squid
Squid12mo ago
Your username is musta_dev and your globalName/displayName is Musta Your current code is checking the wrong property for the wrong username
Musta
MustaOP12mo ago
thank you, i made this code before the new username update haha
Want results from more Discord servers?
Add your server