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

213
Visualizações
How to create a channel and send a message to it when user logined to server?

How add channel and send message to it by discord bot when user login? Message should include hyper link button.

const Discord = require("discord.js");
const config = require("./config.json");
const { MessageActionRow, MessageButton } = require("discord.js");
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"] });
const prefix = "!";
client.on("messageCreate", function (message) {
    let guild = message.guild;
    if (message.author.bot) return;
    if (!message.content.startsWith(prefix)) return;

    const commandBody = message.content.slice(prefix.length);
    const args = commandBody.split(" ");
    const command = args.shift().toLowerCase();

    if (command === "ping") {
        const timeTaken = Date.now() - message.createdTimestamp;
        message.reply(`Pong! This message had a latency of ${timeTaken}ms.`);
    } else if (command === "sum") {
        const numArgs = args.map((x) => parseFloat(x));
        const sum = numArgs.reduce((counter, x) => (counter += x));
        message.reply(`The sum of all the arguments you provided is ${sum}!`);
    } else if (command === "channel") {
        // Create a new text channel
        guild.channels
            .create("nft-checking", { reason: "Needed a cool new channel" })
            .then(console.log)
            .catch(console.error);
    }
});

// client.on("ready", (client) => {
//     client.channels.get("938800178314485823").send("Hello here!");
// });
client.login(config.BOT_TOKEN);
console.log("Discord server is running.");

Please check this and let me know correct code.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You would send a message to the channel as you do with any other channel. To get your new channel you would access it in the .then() after you created it. Here's an example:

guild.channels
    .create("nft-checking", { reason: "Needed a cool new channel" })
    .then(channel => {
         channel.send('I am a new channel');
    }).catch(console.error);

In order to run this code when a user joins, you would use the guildMemberAdd event.

For example:

client.on('guildMemberAdd', (member) => {
    const guild = member.guild;
    
    guild.channels
        .create("nft-checking", { reason: "Needed a cool new channel" })
        .then(channel => {
             channel.send('I am a new channel');
        }).catch(console.error);
});

If you would like to make the channel restricted to the new user with permissions you can check the documentation here and look at the options available.

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