Chixel / guilded.js

6 stars 2 forks source link

Exception when bot tries to reply to a message received via DM #2

Open mechanik556 opened 4 years ago

mechanik556 commented 4 years ago

I have a bot which replies to chat messages. It works fine in regular channels but DM's cause an exception.

(node:19080) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'members' of null
    at new Message (C:\Users\Chris\nerdrage_guilded_port\node_modules\guilded.js\src\Message.js:14:16)
    at MessageManager.add (C:\Users\Chris\nerdrage_guilded_port\node_modules\guilded.js\src\MessageManager.js:14:23)
    at MessageReceived.channels.fetch.then (C:\Users\Chris\nerdrage_guilded_port\node_modules\guilded.js\src\Guilded.js:179:46)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:19080) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:19080) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Here's a snippet of my bot code:

const client = new Guilded.Client()

const commands = [
  chop,
  chops,
  roll,
  rollv5,
]

client.on('ready', () => {
  console.log(`Logged in as ${client.user.tag}!`)
})

client.on('message', (msg) => {
  commands.forEach((cmd) => {

    // Guilded messages have many lines... iterate through all lines of the message
    msg.content.forEach((line) => {
      const matches = line.text.match(cmd.regex)
      if (matches !== null) {
        const replies = matches.map(match => cmd.handler(match)).filter(Boolean)
        if (replies.length) msg.reply(replies.join(''), "Die Roll Results")
      }
    })
  })
})

client.login(/* credentials redacted*/)
Sylchi commented 3 years ago

Can confirm. Client throws exception when receiving private message.