Closed Monsupito closed 4 years ago
UP !
Choose one: is this a bug report
Discord = require('discord.js')
Logger = require('./Logger')
module.exports = class WebhookPlugin
constructor: (webhooks) ->
if !webhooks
return null
@webhooks = []
# Here \/
for hook of Object.keys webhooks
@webhooks.push hook
webhookCredentials = webhooks[hook].split('/').slice(-2)
@[hook] =
url: webhooks[hook]
id: webhookCredentials[0]
token: webhookCredentials[1]
@[hook].client = new (Discord.WebhookClient)(@[hook].id, @[hook].token)
send: (webhook, content) ->
if @webhooks and @webhooks.includes(webhook)
if typeof content == 'object' and !(content instanceof Array)
content = embeds: [ content ]
if content
@[webhook].client.send(content).catch Logger.error
The code should be compiled correctly
On this code the function 'for' is not compiled correctly since the 'of' becomes 'in'
I just wanted to compile my program with this command: "coffee --compile --transpile --map --no-header --output dist/ src/
". Everything works fine except that.
Please read the documentation. They are swapped. If you want to iterate over generators, use from.
See https://coffeescript.org/#loops.
CoffeeScript invented for ... of
and for ... in
before they were adopted in JavaScript, and unfortunately the ECMAScript committee decided to choose different meanings for the keywords than CoffeeScript had chosen. We can't change now because we avoid unnecessary breaking changes. Yes it is confusing; blame TC39.
If you want to iterate over an object, CoffeeScript provides for key, val of obj
.
That's how it is in CoffeeScript.
Originally posted by @vendethiel in https://github.com/jashkenas/coffeescript/issues/5313#issuecomment-605660005