Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

/command in one channel and post in another?

My code is: (EDITED)

const channels = [];

const { SlashCommandBuilder } = require('discord.js');

module.exports = {
    data: new SlashCommandBuilder()
        .setName('mainframe')
        .setDescription('bot will post to the mainframe for you.')
        .addStringOption(option =>
            option.setName('post')
                .setDescription('What you would like posted.')
                .setRequired(true)),

async execute(interaction) {
        const post = interaction.options.getString('post');
        
        let response = `"${post}".`;
      
        await interaction.guild.channels.cache.get(channels[getRandomInt(channels.length)]).send({ content: response });
    },
};


    

What I would like is for the bot to accept the command ephemerally and repost what you send it to another channel or randomly pick from array of channel IDs.

As I understand it, this is typically not possible in this direct fashion, according to another answer I’ve seen on here. However this response makes me think the way to do it is to have the bot store the URLs in a collection, and then post it on its own to some directed channel.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Is this possible?

>Solution :

Yes it is possible. You just need to know the id of the specific channel, the message content, embeds (if wanted) and the bot need permission to send messages into that channel. You will need to search in the guild for the channel and then just send the message into the channel like every other normal message:

interaction.guild.channels.cache.get('channelId').send({ content: 'your message' });

If you have further questions just comment on my response.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading