Discord.js: bot on ready event send message

Created on 24 May 2016  路  9Comments  路  Source: discordjs/discord.js

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?

question (please use Discord instead)

All 9 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MattIPv4 picture MattIPv4  路  18Comments

Protected picture Protected  路  26Comments

JMTK picture JMTK  路  20Comments

vladfrangu picture vladfrangu  路  23Comments

appellation picture appellation  路  29Comments