README
Table of Contents generated with DocToc
Client
client.events
Event emitter object https://nodejs.org/api/events.html
client.token
You have to set it on the ready event to actually get the real token
client.events.on('ready', (info) => {
client.token = info.token
})
client.users
Collection of users that can be accessed like below
client.users['ID HERE']
client.userId
User id of the bot that the client is logged in
client.ping()
Returns a ping in milliseconds
async function getPing() {
const ping = await client.ping()
console.log(ping)
}
client.login()
Login with a token
client.login('Token here')
Message
message.content
String of the message content
message.channelId
Channel Id of where the message got posted in
message.id
Id of the message
message.user
message.user.username
Username of the message author will be undefined if there is no username
message.user.id
Id of the message author
message.user.avatarUrl
Avatar url of the message author
message.user.bot
Boolean to check if the user is a bot or not
message.mentions
Array of user ids that have been mentioned in the message
message.send()
Send method that makes the bot send a message in the channel the message came from
message.send('String', {
title: 'Title',
description: 'Description',
imageUrl: 'https://example.com'
})
message.reply()
Same as message.send() except it mentions the author of the message at the begin
Example
const client = require('veld.chat')
client.events.on('ready', (info) => {
console.log('Ready!')
client.token = info.token
console.log(client.token)
})
client.events.on('message', async (message) => {
if (!message.content || message.user.bot || message.user.id === client.userId) {
return
}
console.log(`${message.user.username} (${message.user.id}): ${message.content}`)
const args = message.content.trim().split(' ')
args.shift()
if (message.content.startsWith('?say')) {
message.send(args.join(' '))
}
if (message.content.startsWith('?eval')) {
function clean(text) {
if (typeof text === 'string')
return text.replace(/`/g, '`' + String.fromCharCode(8203)).replace(/@/g, '@' + String.fromCharCode(8203))
else return text
}
try {
const code = args.join(' ')
let evaled = eval(code)
console.log(typeof evaled !== 'string')
if (typeof evaled !== 'string') evaled = require('util').inspect(evaled)
evaled = clean(evaled)
message.send(clean(evaled))
} catch (err) {
message.send(`\`ERROR\` \`\n${clean(err)}\n\``)
}
}
if (message.content === '?ping') {
console.log('Ping command executed')
const ping = await client.ping()
console.log(ping)
try {
message.send(' ', { title: 'Ping Pong!', description: 'My ping is: ' + ping.toString() + 'ms' })
} catch (err) {
console.error(err)
}
}
})
client.login('Insert Token')