I am trying to retrieve a certain channel from an ID or mention. Whenever I retrieve the channel from the guild's list of channels, it is in the form of a GuildChannel
, which cannot directly have messages sent to using .send(message). I've looked briefly through the docs for a way to convert from Guild Channel
to one of TextChannel | DMChannel | NewsChannel but to no avail.
Any help is appreciated, thanks.
I am trying to retrieve a certain channel from an ID or mention. Whenever I retrieve the channel from the guild's list of channels, it is in the form of a GuildChannel
, which cannot directly have messages sent to using .send(message). I've looked briefly through the docs for a way to convert from Guild Channel
to one of TextChannel | DMChannel | NewsChannel but to no avail.
Any help is appreciated, thanks.
Share Improve this question asked Jul 14, 2020 at 15:49 user2896438user2896438 94417 silver badges23 bronze badges1 Answer
Reset to default 5If you are trying to do this based off of a message that was sent then you should be able to use.
message.guild.channels.cache.get("CHANNEL_ID").send("message");
When accessing a channel from cache, it is good to know that the type of channel you receive is a GuildChannel, as the library doesn't know what sort of channel you are retrieving. TextChannel, VoiceChannel, and NewsChannel all inherit from GuildChannel, so intellisense and Typescript will not recognize channel type specific methods and properties such as send()
. If you are indeed retrieving a TextChannel, then the send method will actually be available.
If you are using Typescript and are getting the error Property 'send' does not exist on type 'GuildChannel'.ts(2339)
. You can fix this by first checking the type of the channel and making sure that it is a text channel.
Source: https://github./discordjs/discord.js/issues/3622#issuement-565550605
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745209976a4616778.html
评论列表(0条)