Skip to content

Create thread in slash command execute #1088

Answered by vvito7
ggrantrowberry asked this question in Q&A
Discussion options

You must be logged in to vote

By default, the property channel of CommandInteraction is TextBasedChannel | null. The typedef TextBasedChannels includes the class DMChannel, that does not include the property threads.
You can easily avoid this by typing the channel like this:

const channel = interaction.channel as TextChannel;

Or check if the channel is typed as TextChannel before creating the thread, like this:

const channel = interaction.channel;

if (channel instanceof TextChannel) {
    channel.threads.create({
        name: 'food-talk',
        autoArchiveDuration: 60,
        reason: 'Needed a separate thread for food',
      });
} else {
      interaction.reply('This channel is not a text channel');
}

TextChannel

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@ggrantrowberry
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by almostSouji
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants