refactor: vendor content as regular files (remove git submodules) so CI builds don't need GitHub auth
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
const { Client } = require('../src/index');
|
||||
const client = new Client();
|
||||
|
||||
client.on('ready', async () => {
|
||||
console.log(`${client.user.username} is ready!`);
|
||||
const channel = client.channels.cache.get('id');
|
||||
channel.send({
|
||||
activity: {
|
||||
type: 3, // MessageActivityType.Listen
|
||||
partyId: `spotify:${client.user.id}`,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
client.login('token');
|
||||
@@ -0,0 +1,35 @@
|
||||
'use strict';
|
||||
|
||||
// No longer using 2captcha since the website no longer supports hCaptcha, which Discord uses.
|
||||
const Captcha = require('2captcha');
|
||||
const Discord = require('../src/index');
|
||||
|
||||
const solver = new Captcha.Solver('<2captcha key>');
|
||||
|
||||
const client = new Discord.Client({
|
||||
captchaSolver: function (captcha, UA) {
|
||||
return solver
|
||||
.hcaptcha(captcha.captcha_sitekey, 'discord.com', {
|
||||
invisible: 1,
|
||||
userAgent: UA,
|
||||
data: captcha.captcha_rqdata,
|
||||
})
|
||||
.then(res => res.data);
|
||||
},
|
||||
TOTPKey: '<string>',
|
||||
});
|
||||
|
||||
client.on('ready', async () => {
|
||||
console.log('Ready!', client.user.tag);
|
||||
// Note
|
||||
// You need to include `guild_id` to invite the bot
|
||||
// These two fields can appear either in the URL or in the options.
|
||||
await client.authorizeURL(
|
||||
`https://discord.com/api/oauth2/authorize?client_id=289066747443675143&permissions=414501424448&scope=bot%20applications.commands`,
|
||||
{
|
||||
guild_id: 'guild id',
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
client.login('token');
|
||||
@@ -0,0 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
const Discord = require('../src/index');
|
||||
|
||||
const client = new Discord.Client();
|
||||
|
||||
client.on('ready', async () => {
|
||||
console.log('Ready!', client.user.tag);
|
||||
await client.installUserApps('936929561302675456'); // Midjourney
|
||||
});
|
||||
|
||||
client.login('token');
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
const { Client } = require('../src/index');
|
||||
const client = new Client();
|
||||
|
||||
client.on('ready', async () => {
|
||||
console.log(`${client.user.username} is ready!`);
|
||||
});
|
||||
|
||||
client.on("messageCreate", message => {
|
||||
if (message.content == 'ping') {
|
||||
message.reply('pong');
|
||||
}
|
||||
});
|
||||
|
||||
client.login('token');
|
||||
@@ -0,0 +1,37 @@
|
||||
const { Client } = require('../src/index');
|
||||
const client = new Client();
|
||||
|
||||
client.on('ready', async () => {
|
||||
console.log(`${client.user.username} is ready!`);
|
||||
const channel = client.channels.cache.get('channel id');
|
||||
const message = await channel.send({
|
||||
poll: {
|
||||
question: {
|
||||
text: 'What is your favorite color?',
|
||||
},
|
||||
answers: [{ text: 'Red', emoji: '🍎' }, { text: 'Green', emoji: '🥗' }, { text: 'Blue', emoji: '💙' }, { text: 'Yellow', emoji: '🟡' }],
|
||||
duration: 8,
|
||||
allowMultiselect: true,
|
||||
},
|
||||
});
|
||||
|
||||
console.log(message.poll);
|
||||
// Multi select
|
||||
await message.vote(1, 3);
|
||||
});
|
||||
|
||||
client.on('messagePollVoteAdd', (answer, userId) => {
|
||||
console.log(`User ${userId} voted for answer ${answer.id}`);
|
||||
});
|
||||
|
||||
client.on('messagePollVoteRemove', (answer, userId) => {
|
||||
console.log(`User ${userId} removed their vote for answer ${answer.id}`);
|
||||
});
|
||||
|
||||
client.on('messageUpdate', async (_oldMessage, newMessage) => {
|
||||
if (!newMessage.poll) return;
|
||||
|
||||
console.log('Poll was updated', newMessage.poll);
|
||||
});
|
||||
|
||||
client.login('token');
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
const { Client, WebEmbed } = require('../src/index');
|
||||
const client = new Client();
|
||||
|
||||
client.on('ready', async () => {
|
||||
console.log(`${client.user.username} is ready!`);
|
||||
});
|
||||
|
||||
client.on('messageCreate', message => {
|
||||
if (message.content == 'embed_hidden_url') {
|
||||
const embed = new WebEmbed()
|
||||
.setAuthor({ name: 'hello', url: 'https://google.com' })
|
||||
.setColor('RED')
|
||||
.setDescription('description uh')
|
||||
.setProvider({ name: 'provider', url: 'https://google.com' })
|
||||
.setTitle('This is Title')
|
||||
.setURL('https://google.com')
|
||||
.setImage('https://i.ytimg.com/vi/iBP8HambzpY/maxresdefault.jpg')
|
||||
.setRedirect('https://www.youtube.com/watch?v=iBP8HambzpY')
|
||||
.setVideo('http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4');
|
||||
message.channel.send({
|
||||
content: `Hello world ${WebEmbed.hiddenEmbed}${embed}`,
|
||||
});
|
||||
}
|
||||
if (message.content == 'embed') {
|
||||
const embed = new WebEmbed()
|
||||
.setAuthor({ name: 'hello', url: 'https://google.com' })
|
||||
.setColor('RED')
|
||||
.setDescription('description uh')
|
||||
.setProvider({ name: 'provider', url: 'https://google.com' })
|
||||
.setTitle('This is Title')
|
||||
.setURL('https://google.com')
|
||||
.setImage('https://i.ytimg.com/vi/iBP8HambzpY/maxresdefault.jpg')
|
||||
.setRedirect('https://www.youtube.com/watch?v=iBP8HambzpY')
|
||||
.setVideo('http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4');
|
||||
message.channel.send({
|
||||
content: `${embed}`,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
client.login('token');
|
||||
@@ -0,0 +1,27 @@
|
||||
'use strict';
|
||||
|
||||
// No longer using 2captcha since the website no longer supports hCaptcha, which Discord uses.
|
||||
const Captcha = require('2captcha');
|
||||
const Discord = require('../src/index');
|
||||
|
||||
const solver = new Captcha.Solver('<2captcha key>');
|
||||
|
||||
const client = new Discord.Client({
|
||||
captchaSolver: function (captcha, UA) {
|
||||
return solver
|
||||
.hcaptcha(captcha.captcha_sitekey, 'discord.com', {
|
||||
invisible: 1,
|
||||
userAgent: UA,
|
||||
data: captcha.captcha_rqdata,
|
||||
})
|
||||
.then(res => res.data);
|
||||
},
|
||||
captchaRetryLimit: 3,
|
||||
});
|
||||
|
||||
client.on('ready', async () => {
|
||||
console.log('Ready!', client.user.tag);
|
||||
await client.acceptInvite('mdmc');
|
||||
});
|
||||
|
||||
client.login('token');
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
'use strict';
|
||||
|
||||
const Discord = require('../src/index');
|
||||
const { ProxyAgent } = require('proxy-agent');
|
||||
|
||||
const proxy = new ProxyAgent({
|
||||
getProxyForUrl: function () {
|
||||
return '<any proxy>';
|
||||
},
|
||||
});
|
||||
|
||||
const client = new Discord.Client({
|
||||
ws: {
|
||||
agent: proxy, // WebSocket Proxy
|
||||
// Do not use the `proxy` option if you don't need to use the WebSocket Proxy
|
||||
},
|
||||
http: {
|
||||
// API Proxy
|
||||
// Read more: https://github.com/nodejs/undici/blob/main/docs/docs/api/ProxyAgent.md
|
||||
// agent: ProxyAgentOptions
|
||||
agent: 'my.proxy.server',
|
||||
// or new URL('my.proxy.server')
|
||||
// or { uri: 'my.proxy.server' }
|
||||
},
|
||||
});
|
||||
|
||||
// So if you only need to use the API Proxy (for the purpose of saving data), you don't need to install `proxy-agent`.
|
||||
|
||||
client.on('ready', async () => {
|
||||
console.log('Ready!', client.user.tag);
|
||||
});
|
||||
|
||||
client.login('token');
|
||||
@@ -0,0 +1,47 @@
|
||||
const { Client, RichPresence, CustomStatus, SpotifyRPC } = require('discord.js-selfbot-v13');
|
||||
const client = new Client();
|
||||
|
||||
client.on('ready', async () => {
|
||||
console.log(`${client.user.username} is ready!`);
|
||||
const getExtendURL = await RichPresence.getExternal(
|
||||
client,
|
||||
'367827983903490050',
|
||||
'https://assets.ppy.sh/beatmaps/1550633/covers/list.jpg', // Required if the image you use is not in Discord
|
||||
);
|
||||
const status = new RichPresence(client)
|
||||
.setApplicationId('367827983903490050')
|
||||
.setType('PLAYING')
|
||||
.setURL('https://www.youtube.com/watch?v=5icFcPkVzMg') // If you set a URL, it will automatically change to STREAMING type
|
||||
.setState('Arcade Game')
|
||||
.setName('osu!')
|
||||
.setDetails('MariannE - Yooh')
|
||||
.setParty({
|
||||
max: 8,
|
||||
current: 1,
|
||||
})
|
||||
.setStartTimestamp(Date.now())
|
||||
.setAssetsLargeImage(getExtendURL[0].external_asset_path) // https://assets.ppy.sh/beatmaps/1550633/covers/list.jpg
|
||||
.setAssetsLargeText('Idle')
|
||||
.setAssetsSmallImage('373370493127884800') // https://discord.com/api/v9/oauth2/applications/367827983903490050/assets
|
||||
.setAssetsSmallText('click the circles')
|
||||
.setPlatform('desktop')
|
||||
.addButton('Beatmap', 'https://osu.ppy.sh/beatmapsets/1391659#osu/2873429');
|
||||
// Custom Status
|
||||
const custom = new CustomStatus(client).setEmoji('😋').setState('yum');
|
||||
// Spotify
|
||||
const spotify = new SpotifyRPC(client)
|
||||
.setAssetsLargeImage('spotify:ab67616d00001e02768629f8bc5b39b68797d1bb') // Image ID
|
||||
.setAssetsSmallImage('spotify:ab6761610000f178049d8aeae802c96c8208f3b7') // Image ID
|
||||
.setAssetsLargeText('未来茶屋 (vol.1)') // Album Name
|
||||
.setState('Yunomi; Kizuna AI') // Artists
|
||||
.setDetails('ロボットハート') // Song name
|
||||
.setStartTimestamp(Date.now())
|
||||
.setEndTimestamp(Date.now() + 1_000 * (2 * 60 + 56)) // Song length = 2m56s
|
||||
.setSongId('667eE4CFfNtJloC6Lvmgrx') // Song ID
|
||||
.setAlbumId('6AAmvxoPoDbJAwbatKwMb9') // Album ID
|
||||
.setArtistIds('2j00CVYTPx6q9ANbmB2keb', '2nKGmC5Mc13ct02xAY8ccS'); // Artist IDs
|
||||
|
||||
client.user.setPresence({ activities: [status, custom, spotify] });
|
||||
});
|
||||
|
||||
client.login('token');
|
||||
@@ -0,0 +1,17 @@
|
||||
const { Client } = require('../src/index');
|
||||
|
||||
const client = new Client();
|
||||
|
||||
client.on('ready', async () => {
|
||||
client.user.setSamsungActivity('com.YostarJP.BlueArchive', 'START');
|
||||
|
||||
setTimeout(() => {
|
||||
client.user.setSamsungActivity('com.miHoYo.bh3oversea', 'UPDATE');
|
||||
}, 30_000);
|
||||
|
||||
setTimeout(() => {
|
||||
client.user.setSamsungActivity('com.miHoYo.GenshinImpact', 'STOP');
|
||||
}, 60_000);
|
||||
});
|
||||
|
||||
client.login('token');
|
||||
@@ -0,0 +1,129 @@
|
||||
# Slash command
|
||||
|
||||
```js
|
||||
TextBasedChannel.sendSlash(
|
||||
user: BotId (Snowflake) | User (User.bot === true),
|
||||
commandName: 'command_name [sub_group] [sub]',
|
||||
...args: (string|number|boolean|FileLike|undefined)[],
|
||||
): Promise<Message<true> | Modal>
|
||||
```
|
||||
|
||||
## Basic
|
||||
|
||||
### Demo
|
||||
|
||||

|
||||
|
||||
### Code
|
||||
|
||||
```js
|
||||
await channel.sendSlash('bot_id', 'aiko')
|
||||
```
|
||||
|
||||
## Sub Command / Sub Group
|
||||
|
||||
### Demo
|
||||
|
||||

|
||||
|
||||
### Code test
|
||||
|
||||
```js
|
||||
await channel.sendSlash('450323683840491530', 'animal chat', 'bye')
|
||||
```
|
||||
|
||||
## Attachment
|
||||
|
||||
### Demo
|
||||
|
||||

|
||||
|
||||
### Code test
|
||||
|
||||
```js
|
||||
const { MessageAttachment } = require('discord.js-selfbot-v13')
|
||||
const fs = require('fs')
|
||||
const a = new MessageAttachment(fs.readFileSync('./wallpaper.jpg') , 'test.jpg')
|
||||
await message.channel.sendSlash('718642000898818048', 'sauce', a)
|
||||
```
|
||||
|
||||
### Result
|
||||
|
||||

|
||||
|
||||
## Skip options
|
||||
|
||||
### Demo Command
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
### Code
|
||||
```js
|
||||
const channel = client.channels.cache.get('channel_id');
|
||||
const response = await channel.sendSlash(
|
||||
'bot_id',
|
||||
'image make',
|
||||
'MeinaMix - v11',
|
||||
'Phone (9:16) [576x1024 | 810x1440]',
|
||||
'2', // String choices, not number
|
||||
undefined, // VAE
|
||||
undefined, // sdxl_refiner
|
||||
undefined, // sampling_method,
|
||||
30,
|
||||
);
|
||||
// Submit Modal
|
||||
if (!response.isMessage) { // Modal
|
||||
response.components[0].components[0].setValue(
|
||||
'1girl, brown hair, green eyes, colorful, autumn, cumulonimbus clouds',
|
||||
);
|
||||
response.components[1].components[0].setValue(
|
||||
'(worst quality:1.4), (low quality:1.4), (normal quality:1.4), (ugly:1.4), (bad anatomy:1.4), (extra limbs:1.2), (text, error, signature, watermark:1.2), (bad legs, incomplete legs), (bad feet), (bad arms), (bad hands, too many hands, mutated hands), (zombie, sketch, interlocked fingers, comic, morbid), cropped, long neck, lowres, missing fingers, missing arms, missing legs, extra fingers, extra digit, fewer digits, jpeg artifacts',
|
||||
);
|
||||
await response.reply();
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
### Receive messages after bot has replied `{botname} is thinking...`
|
||||
|
||||
> [aiko-chan-ai/discord.js-selfbot-v13#1055 (comment)](https://github.com/aiko-chan-ai/discord.js-selfbot-v13/issues/1055#issuecomment-1949653100)
|
||||
|
||||

|
||||
|
||||
```js
|
||||
const channel = client.channels.cache.get('id');
|
||||
channel
|
||||
.sendSlash('289066747443675143', 'osu', 'Accolibed')
|
||||
.then(async (message) => {
|
||||
if (message.flags.has('LOADING')) { // owo is thinking...
|
||||
return new Promise((resolve, reject) => {
|
||||
let done = false;
|
||||
const timeout = setTimeout(() => {
|
||||
if (!done) {
|
||||
done = true;
|
||||
client.off('messageUpdate', onUpdate);
|
||||
reject('timeout');
|
||||
}
|
||||
}, 15 * 60 * 1000); // 15m (DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE)
|
||||
|
||||
function onUpdate(_, m) {
|
||||
if (_.id === message.id) {
|
||||
if (!done) {
|
||||
done = true;
|
||||
clearTimeout(timeout);
|
||||
client.off('messageUpdate', onUpdate);
|
||||
resolve(m);
|
||||
}
|
||||
}
|
||||
}
|
||||
client.on('messageUpdate', onUpdate);
|
||||
});
|
||||
} else {
|
||||
return Promise.resolve(message);
|
||||
}
|
||||
})
|
||||
.then(console.log);
|
||||
```
|
||||
@@ -0,0 +1,30 @@
|
||||
// Join a voice channel and do nothing
|
||||
|
||||
/*
|
||||
Install:
|
||||
- An Opus library: @discordjs/opus or opusscript
|
||||
- An encryption packages:
|
||||
+ sodium (best performance)
|
||||
+ libsodium-wrappers
|
||||
+ @stablelib/xchacha20poly1305
|
||||
- ffmpeg (install and add to your system environment)
|
||||
*/
|
||||
|
||||
const { Client } = require('../../src/index');
|
||||
const client = new Client();
|
||||
|
||||
client.on('ready', async () => {
|
||||
console.log(`${client.user.username} is ready!`);
|
||||
const channel = client.channels.cache.get('voice_channel');
|
||||
const connection = await client.voice.joinChannel(channel, {
|
||||
selfMute: true,
|
||||
selfDeaf: true,
|
||||
selfVideo: false,
|
||||
});
|
||||
// Leave voice
|
||||
setTimeout(() => {
|
||||
connection.disconnect();
|
||||
}, 5_000);
|
||||
});
|
||||
|
||||
client.login('token');
|
||||
@@ -0,0 +1,58 @@
|
||||
// Join a channel and play music, like a Discord bot.
|
||||
|
||||
/*
|
||||
Install:
|
||||
- An Opus library: @discordjs/opus or opusscript
|
||||
- An encryption packages:
|
||||
+ sodium (best performance)
|
||||
+ libsodium-wrappers
|
||||
+ @stablelib/xchacha20poly1305
|
||||
- ffmpeg (install and add to your system environment)
|
||||
*/
|
||||
|
||||
|
||||
const { Client } = require('../../src/index');
|
||||
const ytdl = require('@distube/ytdl-core'); // better than ytdl-core
|
||||
const client = new Client();
|
||||
|
||||
client.on('ready', async client => {
|
||||
console.log(`${client.user.username} is ready!`);
|
||||
const channel = client.channels.cache.get('voice_id');
|
||||
const connection = await client.voice.joinChannel(channel, {
|
||||
selfMute: true,
|
||||
selfDeaf: true,
|
||||
selfVideo: false,
|
||||
});
|
||||
const dispatcher = connection.playAudio(
|
||||
ytdl('https://www.youtube.com/watch?v=3KadWjpqDXs', {
|
||||
quality: 'highestaudio',
|
||||
}),
|
||||
);
|
||||
dispatcher.on('start', () => {
|
||||
console.log('audio is now playing!');
|
||||
// pause
|
||||
console.log('paused');
|
||||
dispatcher.pause();
|
||||
// resume
|
||||
setTimeout(() => {
|
||||
console.log('resumed');
|
||||
dispatcher.resume();
|
||||
}, 5_000);
|
||||
|
||||
// Set volume
|
||||
dispatcher.setVolume(0.5);
|
||||
console.log('50% volume');
|
||||
});
|
||||
|
||||
dispatcher.on('finish', () => {
|
||||
console.log('audio has finished playing!');
|
||||
});
|
||||
dispatcher.on('error', console.error);
|
||||
// Leave voice
|
||||
setTimeout(() => {
|
||||
console.log('disconnected');
|
||||
connection.disconnect();
|
||||
}, 30_000);
|
||||
});
|
||||
|
||||
client.login('token');
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
Credit: https://github.com/dank074/Discord-video-stream
|
||||
The use of video streaming in this library is an incomplete implementation with many bugs, primarily aimed at lazy users.
|
||||
The video streaming features in this library are sourced from https://github.com/dank074/Discord-video-stream.
|
||||
|
||||
Please use the @dank074/discord-video-stream library to access all advanced and professional features,
|
||||
along with comprehensive support. I will not actively fix bugs related to streaming and encourage everyone to
|
||||
use https://github.com/dank074/Discord-video-stream for stable and smooth streaming.
|
||||
|
||||
To reiterate: This is an incomplete implementation of the library https://github.com/dank074/Discord-video-stream.
|
||||
|
||||
Thanks to dank074 and longnguyen2004 for implementing new codecs (H264, H265).
|
||||
Thanks to mrjvs for discovering how Discord transmits data and the VP8 codec.
|
||||
|
||||
Please use the @dank074/discord-video-stream library for the best support.
|
||||
*/
|
||||
|
||||
/*
|
||||
Install:
|
||||
- An Opus library: @discordjs/opus or opusscript
|
||||
- An encryption packages:
|
||||
+ sodium (best performance)
|
||||
+ libsodium-wrappers
|
||||
+ @stablelib/xchacha20poly1305
|
||||
- ffmpeg (install and add to your system environment)
|
||||
*/
|
||||
|
||||
const { Client } = require('../../src/index');
|
||||
const client = new Client();
|
||||
|
||||
client.on('ready', async client => {
|
||||
console.log(`${client.user.username} is ready!`);
|
||||
const channel = client.channels.cache.get('voice_channel');
|
||||
const connection = await client.voice.joinChannel(channel, {
|
||||
selfMute: true,
|
||||
selfDeaf: true,
|
||||
selfVideo: false, // Turn on the camera? If you turn on the camera, use the connection similar to
|
||||
// PlayAudio.js, and it will stream video through the camera. This is an implementation of screen sharing.
|
||||
videoCodec: 'H264',
|
||||
});
|
||||
const stream = await connection.createStreamConnection();
|
||||
// You can also access it by using `connection.streamConnection` (only after it has been initialized by the `createStreamConnection` function).
|
||||
// Split it into two separate streams (audio / video)
|
||||
// Or with a combined stream that will be automatically processed by FFmpeg.
|
||||
const input = 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4';
|
||||
// Play
|
||||
const dispatcher = stream.playVideo(input, {
|
||||
fps: 60,
|
||||
bitrate: 4000,
|
||||
});
|
||||
const dispatcher2 = stream.playAudio(input);
|
||||
dispatcher.on('start', () => {
|
||||
console.log('video is now playing!');
|
||||
});
|
||||
|
||||
dispatcher.on('finish', () => {
|
||||
console.log('video has finished playing!');
|
||||
});
|
||||
dispatcher.on('error', console.error);
|
||||
|
||||
dispatcher2.on('start', () => {
|
||||
console.log('audio is now playing!');
|
||||
});
|
||||
|
||||
dispatcher2.on('finish', () => {
|
||||
console.log('audio has finished playing!');
|
||||
});
|
||||
dispatcher2.on('error', console.error);
|
||||
// Of course, you can also pause the stream using the `pause` function, but remember to pause both video and audio.
|
||||
});
|
||||
|
||||
client.login('token');
|
||||
@@ -0,0 +1,54 @@
|
||||
// https://v12.discordjs.guide/voice/receiving-audio.html#basic-usage
|
||||
|
||||
/*
|
||||
Install:
|
||||
- An Opus library: @discordjs/opus or opusscript
|
||||
- An encryption packages:
|
||||
+ sodium (best performance)
|
||||
+ libsodium-wrappers
|
||||
+ @stablelib/xchacha20poly1305
|
||||
- ffmpeg (install and add to your system environment)
|
||||
*/
|
||||
|
||||
|
||||
const { Client } = require('../../src/index');
|
||||
const client = new Client();
|
||||
|
||||
const fs = require('fs');
|
||||
const Speaker = require('speaker');
|
||||
|
||||
client.on('ready', async client => {
|
||||
console.log(`${client.user.username} is ready!`);
|
||||
|
||||
const speaker = new Speaker({
|
||||
channels: 2, // 2 channels
|
||||
bitDepth: 16, // 16-bit samples
|
||||
sampleRate: 48000, // 48000 Hz sample rate
|
||||
});
|
||||
|
||||
const channel = client.channels.cache.get('voice_id');
|
||||
const connection = await client.voice.joinChannel(channel, {
|
||||
selfMute: true,
|
||||
selfDeaf: true,
|
||||
selfVideo: false,
|
||||
});
|
||||
|
||||
const audio = connection.receiver.createStream('user_id', {
|
||||
mode: 'pcm',
|
||||
end: 'manual',
|
||||
paddingSilence: true,
|
||||
});
|
||||
|
||||
audio.pipe(fs.createWriteStream('test.pcm'));
|
||||
|
||||
// After 15s
|
||||
setTimeout(() => {
|
||||
console.log('Stop recording');
|
||||
audio.destroy();
|
||||
// Play this record...
|
||||
fs.createReadStream('test.pcm').pipe(speaker);
|
||||
}, 15_000);
|
||||
});
|
||||
|
||||
|
||||
client.login('token');
|
||||
@@ -0,0 +1,45 @@
|
||||
// https://v12.discordjs.guide/voice/receiving-audio.html#basic-usage
|
||||
|
||||
/*
|
||||
Install:
|
||||
- An Opus library: @discordjs/opus or opusscript
|
||||
- An encryption packages:
|
||||
+ sodium (best performance)
|
||||
+ libsodium-wrappers
|
||||
+ @stablelib/xchacha20poly1305
|
||||
- ffmpeg (install and add to your system environment)
|
||||
*/
|
||||
|
||||
const { Client } = require('../../src/index');
|
||||
const client = new Client();
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
client.on('ready', async client => {
|
||||
console.log(`${client.user.username} is ready!`);
|
||||
|
||||
const channel = client.channels.cache.get('voice_id');
|
||||
const connection = await client.voice.joinChannel(channel, {
|
||||
selfMute: true,
|
||||
selfDeaf: true,
|
||||
selfVideo: false,
|
||||
});
|
||||
|
||||
const connectionStream = await connection.joinStreamConnection('user_id');
|
||||
|
||||
const video = connectionStream.receiver.createVideoStream('user_id', fs.createWriteStream('video.mkv')); // Output file using matroska container
|
||||
|
||||
video.on('ready', () => {
|
||||
console.log('FFmpeg process ready!');
|
||||
video.stream.stderr.on('data', data => {
|
||||
console.log(`FFmpeg: ${data}`);
|
||||
});
|
||||
});
|
||||
|
||||
// After 15s
|
||||
setTimeout(() => {
|
||||
video.destroy();
|
||||
}, 15_000);
|
||||
});
|
||||
|
||||
client.login('token');
|
||||
@@ -0,0 +1,21 @@
|
||||
const { Client, MessageAttachment } = require('../src/index');
|
||||
const client = new Client();
|
||||
|
||||
client.on('ready', async () => {
|
||||
console.log(`${client.user.username} is ready!`);
|
||||
const channel = client.channels.cache.get('channel_id');
|
||||
const attachment = new MessageAttachment(
|
||||
'./test.mp3', // path file
|
||||
'random_file_name.ogg', // must be .ogg
|
||||
{
|
||||
waveform: 'AAAAAAAAAAAA',
|
||||
duration_secs: 1, // any number you want
|
||||
},
|
||||
);
|
||||
channel.send({
|
||||
files: [attachment],
|
||||
flags: 'IS_VOICE_MESSAGE',
|
||||
});
|
||||
});
|
||||
|
||||
client.login('token');
|
||||
Reference in New Issue
Block a user