JavaScript

(for advanced users)

Index

Notes

  • Bot Designer for Discord allows you to use JavaScript (ES2015).
  • Discord's API is not fully supported yet but there will be more extensive support in the future.
  • Callbacks don't support JavaScript at the moment.

Accessing JavaScript

1: Go to user settings in the BDFD app, and enable "Features for Advanced Users".

jswiki1

jswiki2

2: After to creating a new command, set the Scripting Language to "JavaScript".

jswiki3

jswiki4

Available Objects in Commands

NameTypeDescription
messagestringContains author's message.
commandPrefixstringContains the trigger of this command.
authorIdstringContains the ID of the user that executed this command.
channelIdstringContains channel ID where the command was used.
userMentionsarray of string valuesContains user mentions.
roleMentionsarray of string valuesContains role mentions.

Supported API Functions

NameDescription
setResponse(replyText)Where replyText is a string value. Sends a message to the channel where the command was used.
setEmbedResponse(title, description, footer)Where title, description, footer are string values. Sends a embedded message to the channel where the command was used.
setEmbedImage(imageURL)Where imageURL is a string value. Sets image of the embedded message.
ban(userID)Where userID is a string value. Bans a user.
banWithReason(userID, reason)Where userID and reason are string values. Bans a user with reason.
unban(userID)Where userID is a string value. Unbans the user.
kick(userID)Where userID is a string value. Kicks a user.
kickWithReason(userID, reason)Where userID and reason are string values. Kicks a user with reason.
giveRole(userID, roleID)Where userID and roleID are string values. Gives a role to the user.
takeRole(userID, roleID)Where userID and roleID are string values. Removes a role from the user.
channelTyping()Shows "Bot is typing..." message.
createChannel(name, type)Where name and type are string values (type must be text or voice). Creates a channel. Providing wrong type will result in throwing an exception which you can catch.
removeChannel(channelID)Where channelID is a string value. Deletes a channel.
pinMessage(channelID, messageID)Where channelID and messageID are string values. Pins a message.
unpinMessage(channelID, messageID)Where channelID and messageID are string values. Unpins a pinned message.
sendChannelMessage(channelID, message)Where channelID and message are string values. Sends message to the provided channel.

Example

(say command)

var text = message.replace(commandPrefix, " ") // Makes 'text' the user's message without the command trigger.
setResponse(text) // Sets the response as 'text'.

image