Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

596
Views
How do I get the bot to write user's name

This is the code, I want it to write user's name and then auction word (p.s I am new to this)

const Discord = require('discord.js')
const client = new Discord.Client()
const { MessageEmbed } = require('discord.js');
const channel = client.channels.cache.get('889459156782833714');


client.on("ready", () => {
    console.log(`Logged in as ${client.user.tag}!`)
})

client.on("message", msg => {
    var message = new Discord.MessageEmbed()
        .setColor('#FF0000')
        .setTitle() // want user's name + "Auction"
        .addField('Golden Poliwag', 'Very Pog', true)
        .setImage('https://graphics.tppcrpg.net/xy/golden/060M.gif')
        .setFooter('Poliwag Auction')
  
    if (msg.content === "d.test") {
        msg.reply(message)
    }
})
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can access the user's username by using msg.author.tag. So. the way to use the user's tag in an embed would be:

const { MessageEmbed, Client } = require("discord.js");
const client = new Client();

const channel = client.channels.cache.get("889459156782833714");

client.on("ready", () => {
    console.log(`Logged in as ${client.user.tag}!`);
});

client.on("message", (msg) => {
    var message = new Discord.MessageEmbed()
        .setColor("#FF0000")
        .setTitle(`${msg.author.tag} Auction`)
        .addField("Golden Poliwag", "Very Pog", true)
        .setImage("https://graphics.tppcrpg.net/xy/golden/060M.gif")
        .setFooter("Poliwag Auction");
    if (msg.content === "d.test") {
        msg.reply(message);
    }
});
about 4 years ago · Juan Pablo Isaza Report

0

I suggest you to read the discord.js documentation, almost all you need to interact with Discord API is from there.

  1. You can't control the bot if you don't login to it. Get the bot's token from Developer Portal and login to your bot by adding client.login('<Your token goes here>') in your project.

  2. You can't get the channel if it's not cached in the client. You need to fetch it by using fetch() method from client's channels manager:

const channel = await client.channels.fetch('Channel ID goes here');

P/s: await is only available in async function

  1. message event is deprecated if you are using discord.js v13. Please use messageCreate event instead.

  2. You are able to access user who sent the message through msg object: msg.author. If you want their tag, you can get the tag property from user: msg.author.tag, or username: msg.author.username or even user ID: msg.author.id. For more information about discord message class read here.

  3. The reply options for message is not a message. You are trying to reply the message of the author with another message which is wrong. Please replace the reply options with an object that includes embeds:

msg.reply({ 
    embeds: [
        // Your array of embeds goes here
    ]
});

From all of that, we now have the final code:

const { Client, MessageEmbed } = require('discord.js');
const client = new Client();

client.on("ready", () => {console.log(`Logged in as ${client.user.tag}!`)});

client.on("messageCreate", async (msg) => {
    const channel = await client.channels.fetch('889459156782833714');
    const embed = new Discord.MessageEmbed()
        .setColor('#FF0000')
        .setTitle(`${msg.author.tag} Auction`)
        .addField('Golden Poliwag','Very Pog',true)
        .setImage('https://graphics.tppcrpg.net/xy/golden/060M.gif')
        .setFooter('Poliwag Auction');
    if (msg.content === "d.test") {
        msg.reply({
            embeds: [ embed ],
        });
    }
});

client.login('Your bot token goes here');

Now your bot can reply to command user with an rich embed.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!