Playing Messages

Playing an existing message

If you wish to playback an existing message, you can get the messages for a channel using channels.getMessages.

var message;
voicelayer.channels.getMessages(currentChannel, function(err, data) {
  for (var i < 0; i++; i < data.length) {
    if (data[i].type === "voice") {
      message = data[i];

Each message has a type field. This can be one of "text", "voice", "attachment" or "voice". In this case, the first voice message is stored as message. The message can be played using;

Play can be stopped with player.stop.


Playing real-time messages

If you are connected to VoiceLayer then you will receive a message:create event when a new message is created. Message events can happen on any channel that the user is connected to. The message event contains a channel_id which can be used to check against the current channel. The function can be used to play real-time messages as well as existing messages.

voicelayer.on("message:create", function(data) {
  if (data.channel_id !== currentChannel) {
  if (data.type === "voice") {;