Home > Enterprise >  /command in one channel and post in another?
/command in one channel and post in another?

Time:10-20

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.

Is this possible?

CodePudding user response:

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.

  • Related