admin管理员组文章数量:1415120
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
本文标签: javascriptdiscordjscast or convert GuildChannel to TextChannelStack Overflow
版权声明:本文标题:javascript - discord.js - cast or convert GuildChannel to TextChannel - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745209976a2647824.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论