# voltra.api

> The most simple way to create a bot for voltra.tk

Latest version **1.1.7** (published 2021-04-10) · ISC license · 0 weekly downloads

## Install

```sh
npm install voltra.api
pnpm add voltra.api
yarn add voltra.api
bun add voltra.api
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.7 |
| Published | 2021-04-10 |
| First published | 2021-04-02 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 11.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | dxy_seer |

## Links

- npm: https://www.npmjs.com/package/voltra.api
- Repository: https://github.com/Voltra-tk/api-wrapper
- Homepage: https://github.com/Voltra-tk/api-wrapper#readme
- Issues: https://github.com/Voltra-tk/api-wrapper/issues
- npm.io page: https://npm.io/package/voltra.api

## Dependencies (3)

- [chalk](https://npm.io/package/chalk.md) ^4.1.0
- [node-fetch](https://npm.io/package/node-fetch.md) ^2.6.1
- [socket.io-client](https://npm.io/package/socket.io-client.md) ^4.0.1

## Recent versions

- 1.1.7 (latest) — 2021-04-10
- 1.1.6 — 2021-04-10
- 1.1.5 — 2021-04-07
- 1.1.4 — 2021-04-07
- 1.1.3 — 2021-04-07
- 1.1.2 — 2021-04-05
- 1.1.1 — 2021-04-04
- 1.1.0 — 2021-04-04
- 1.0.9 — 2021-04-03
- 1.0.8 — 2021-04-03
- 1.0.7 — 2021-04-03
- 1.0.6 — 2021-04-03
- 1.0.5 — 2021-04-03
- 1.0.4 — 2021-04-03
- 1.0.3 — 2021-04-03
- … 3 more at https://npm.io/package/voltra.api/versions

## README

# Voltra.api

- [Refrences](#refrences) 
- [Examples](#examples)
- [OAuth](#oauth)


### Refrences

```js
const voltraApi = require('voltra.api'); // import the package
```

```js
const api = new voltraApi.client('SID TOKEN'); // Initiate the bot
```

```js
api.socket.onMessage('CHANNEL ID', async (msg) => { // Open a websocket to receive messages from a channel
    // ...
});
```

```js
const userObj = await api.socket.getUser('USERID'); // Get the user object
```

```js
api.joinGuild('guildid'); // Join a guild
``` 

```js
api.socket.sendMessage('messagecontent', false); // set to true to send a message type of 100
```

```js
api.changeSettings('newusername', 'avatarurl')
```

```js
api.socket.me // EXPERIMENTAL: Gives the bot's user object.
```

### Examples

Simple bot connected to multiple channels:

```js
const voltra = require('voltra.api');
const api = new voltra.client('BOT_TOKEN');
const prefix = '!';

(async () => {
    async function joinGuild(id){ // join guild function (Callable)
        return await api.joinGuild(id); 
    }
    api.socket.onMessage('channel1', async (message) => { // Provide a channel id here to connect and receive messages
        console.log(`${message.author.username}:`, message.string)

        if(!message.string.startsWith(prefix) || message.author.bot) return;
        const args = message.string.slice(prefix.length).trim().split(' ');
        const command = args.shift().toLowerCase();

        if(command == 'commandname'){
           // ...
        }
    });

    api.socket.onMessage('channel2', async (message) => { // Provide a channel id here to connect and receive messages
        console.log(`${message.author.username}:`, message.string)

        if(!message.string.startsWith(prefix) || message.author.bot) return;
        const args = message.string.slice(prefix.length).trim().split(' ');
        const command = args.shift().toLowerCase();

        if(command == 'commandname'){
           // ...
        }
    });
})()
```

### OAuth

```js
const oauth = new voltra.oauth(); // new client
```

```js
const user = await oauth.authorize(); // authorize user by token
console.log('OAuth >', user) // log user
```

---
_Source: https://npm.io/package/voltra.api · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
