Guest User

Untitled

a guest
Nov 13th, 2025
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. const fs = require('fs');
  2. const path = require('path');
  3. const gTTS = require('gtts');
  4. const { Client, GatewayIntentBits } = require('discord.js');
  5. const {
  6. joinVoiceChannel,
  7. createAudioPlayer,
  8. createAudioResource,
  9. AudioPlayerStatus,
  10. StreamType
  11. } = require('@discordjs/voice');
  12.  
  13. const { TOKEN, GUILD_ID, VOICE_CHANNEL_ID } = require('./config');
  14.  
  15. const client = new Client({
  16. intents: [GatewayIntentBits.GuildVoiceStates]
  17. });
  18.  
  19. client.once('ready', async () => {
  20. console.log(`Logged in as ${client.user.tag}`);
  21.  
  22. try {
  23. const guild = await client.guilds.fetch(GUILD_ID);
  24. const channel = await guild.channels.fetch(VOICE_CHANNEL_ID);
  25.  
  26. if (!channel || channel.type !== 2) {
  27. console.log('❌ Это не голосовой канал или ID неверный');
  28. return;
  29. }
  30.  
  31. const connection = joinVoiceChannel({
  32. channelId: channel.id,
  33. guildId: guild.id,
  34. adapterCreator: guild.voiceAdapterCreator,
  35. selfDeaf: false,
  36. });
  37.  
  38. const player = createAudioPlayer();
  39. connection.subscribe(player);
  40.  
  41. console.log('✅ Бот подключен и слушает lines.txt');
  42.  
  43. // Мониторинг файла
  44. setInterval(() => {
  45. let lines = fs.readFileSync(path.join(__dirname, 'lines.txt'), 'utf-8')
  46. .split('\n')
  47. .filter(Boolean);
  48. if (lines.length == 0) { return }
  49.  
  50. const line = lines.shift(); // берём первую строку
  51. fs.writeFileSync(path.join(__dirname, 'lines.txt'), lines.join('\n')); // удаляем её из файла
  52.  
  53. const audioPath = path.join(__dirname, 'output.mp3');
  54. const tts = new gTTS(line, 'ru');
  55. tts.save(audioPath, () => {
  56. const resource = createAudioResource(fs.createReadStream(audioPath), {
  57. inputType: StreamType.Arbitrary
  58. });
  59. player.play(resource);
  60. });
  61.  
  62. }, 100);
  63.  
  64. } catch (e) {
  65. console.error('Ошибка подключения:', e);
  66. }
  67. });
  68.  
  69. client.login(TOKEN);
  70.  
Advertisement
Add Comment
Please, Sign In to add comment