Discord.js sending a message to a specific channel

后端 未结 4 1871
予麋鹿
予麋鹿 2020-12-20 19:27

I\'m failing to achieve something very simple. I can\'t send a message to a specific channel. I\'ve browsed trough the documentation and similar threads on stack overflow. <

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-20 19:43

    You didn't provide any code that you already tested so I will give you the code for your ready event that will work!

        client.on('ready', client => {
            client.channels.get('CHANNEL ID').send('Hello here!');
        })
    

    Be careful that your channel id a string.

    Let me know if it worked, thank you!

    2020 Jun 13 Edit:

    A Discord.js update requires the cache member of channels before the get method.

    If your modules are legacy the above would still work. My recent solution works changing the send line as follows.

            client.channels.cache.get('CHANNEL ID').send('Hello here!')
    

提交回复
热议问题