Hey guys!
I'm currently writing a small git bot, and yeah.
I'm trying to send a message on ready event. That's my current code:
bot.on('ready', () => {
console.log('ready!');
bot.sendMessage('general', 'test');
});
yeah... I don't receive a message. What I did wrong?
bot.sendMessage() only takes a resolvable so either put a channel object or an actual id in it
thank you very much!
for people w/ the same problem:
First you need to get the channel id (use this code, to get all channels)
console.log(bot.channels);
Then look at the first entry from 'TextChannel', then you can use it like this (USE ID AS STRING):
bot.sendMessage('174428230890160128', 'test');
How would this work now that we have v11
@GlitchMasta47 Hey dude, not sure if you're still trying to accomplish this, but I was searching for a way to do it too.
You need to call sendmessage() on a channel object rather than the client.
client.on('ready', () => {
var channel = client.channels.get('my-unique-channel-id');
channel.sendMessage("Hello world");
});
TypeError: Cannot read property 'sendMessage' of undefined
at Client.client.on (c:\Users\Aaron Tighe\Documents\Sniperbot.js:6:10)
at emitNone (events.js:91:20)
at Client.emit (events.js:185:7)
at WebSocketConnection.triggerReady (c:\Users\Aaron Tighe\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:123:17)
at WebSocketConnection.checkIfReady (c:\Users\Aaron Tighe\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:139:61)
at GuildCreateHandler.handle (c:\Users\Aaron Tighe\node_modules\discord.js\src\client\websocket\packets\handlers\GuildCreate.js:13:31)
at WebSocketPacketManager.handle (c:\Users\Aaron Tighe\node_modules\discord.js\src\client\websocket\packets\WebSocketPacketManager.js:103:65)
at WebSocketConnection.onPacket (c:\Users\Aaron Tighe\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:330:35)
at WebSocketConnection.onMessage (c:\Users\Aaron Tighe\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:293:17)
at WebSocket.onMessage (c:\Users\Aaron Tighe\node_modules\ws\lib\EventTarget.js:99:16)
Please read the dates before necro-posting old issues with errors.
oh
Well I really want this bot to send a message after it joins a channel. what can I do?
You can join the support server instead of _continuing_ to necro-post an old issue.
https://discord.gg/bRCvFy9