Create thread in slash command execute #1088
-
I want to create a thread when I execute a slash command. This is probably really easy to do but I'm trying to follow the guide but I can't figure it out. The guide says
I figured I could use the interaction object passed into the execute callback to get the channel and then create a thread. However the .threads property doesn't exist on it. I tried importing the client from my index.ts and fetching the channel by the id from the channelId property on the interaction object. But the .threads property didn't exist on that either. How can I do this? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
What error did you get, how is |
Beta Was this translation helpful? Give feedback.
-
By default, the property const channel = interaction.channel as TextChannel; Or check if the channel is typed as 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');
}
|
Beta Was this translation helpful? Give feedback.
By default, the property
channel
ofCommandInteraction
isTextBasedChannel | null
. The typedefTextBasedChannels
includes the classDMChannel
, that does not include the propertythreads
.You can easily avoid this by typing the channel like this:
Or check if the channel is typed as
TextChannel
before creating the thread, like this:TextChannel
…