Search code examples
javascriptnode.jsdiscord.js

Linking a discord channel that your bot made in a message Discord.js


I went looking on how to link the discord channel the bot just made in a message but was not able to find a solution that worked.

Here is my current code:

    const guild = client.guilds.cache.get("1057116059750117426");

    const storageBuffer = fs.readFileSync("./src/Storage/storage.json");
    const storageData = JSON.parse(storageBuffer.toString());

    storageData.ticket_id++; // adds one to the ticket number
    const ticketId = storageData.ticket_id;

    await guild.channels.create({
      name: `TICKET-${ticketId}`,
      parent: "1057370813357109308",
    });


    const ChannelName = guild.channel.id
    //Here is were I want to link the channel 

    await interaction.update({
      ephemeral: true,
      content: `Your ticket has been submited \n You can view it here -> ${ChannelName}`,
      components: [],
      embed: [],
    });

Solution

  • guild.channels.create returns the channel created:

    let createdChannel = await guild.channels.create({
      name: `TICKET-${ticketId}`,
      parent: "1057370813357109308",
    });
    

    ...so you can later use it in your message like this:

    content: `Your ticket has been submitted \n You can view it here -> ${createdChannel}`