• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

180
Views
¿Cómo crear un canal y enviarle un mensaje cuando el usuario inició sesión en el servidor?

¿Cómo agregar un canal y enviarle un mensaje mediante el bot de discordia cuando el usuario inicia sesión? El mensaje debe incluir un botón de hipervínculo.

 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.");

Por favor, compruebe esto y hágame saber el código correcto.

almost 3 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Enviaría un mensaje al canal como lo hace con cualquier otro canal. Para obtener su nuevo canal, accedería a él en .then() después de crearlo. Aquí hay un ejemplo:

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

Para ejecutar este código cuando un usuario se une, usaría el evento guildMemberAdd .

Por ejemplo:

 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); });

Si desea restringir el canal al nuevo usuario con permisos, puede consultar la documentación aquí y ver las opciones disponibles.

almost 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error