Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

604
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda