Guest User

Untitled

a guest
Aug 31st, 2024
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. const { Client, GatewayIntentBits, ChannelType, ActivityType } = require('discord.js');
  2. const { joinVoiceChannel, createAudioResource } = require('@discordjs/voice');
  3. const { createAudioPlayer } = require('@discordjs/voice');
  4. const player = createAudioPlayer();
  5. const ses = createAudioResource('./ses.mp3');
  6. const fs = require('fs');
  7. const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates] });
  8. client.once('ready', async () => {
  9. console.log(`Logged in as ${client.user.tag}`);
  10.  
  11. client.user.setPresence({
  12. activities: [{ name: 'The Casino', type: ActivityType.Playing }],
  13. status: 'online',
  14. });
  15.  
  16. try {
  17. const channel = await client.channels.fetch("1278792596101136435");
  18. console.log(`Found voice channel: ${channel.name}`);
  19. if(!channel) return console.error('Voice channel not found.');
  20. if (channel && channel.type === ChannelType.GuildVoice) {
  21. const connection = joinVoiceChannel({
  22. channelId: "1278792596101136435",
  23. guildId: "1278785780302479421",
  24. adapterCreator: channel.guild.voiceAdapterCreator,
  25. selfDeaf: true
  26. });
  27. const subscription = connection.subscribe(player);
  28. console.log(`Joined voice channel: ${channel.name}`);
  29. } else {
  30. console.error('Voice channel not found or not a voice channel.');
  31. }
  32. } catch (error) {
  33. console.error(`Could not join voice channel: ${error}`);
  34. }
  35. });
  36. client.on('voiceStateUpdate', async (oldState, newState) => {
  37. const giren = await client.users.fetch(newState.member.id)
  38. if(giren.bot) return;
  39. console.log("biri girdi")
  40. player.play(ses)
  41. })
  42. player.on('error', error => {
  43. console.error(`Error: ${error.message}`);
  44. player.play(getNextResource());
  45. });
  46.  
  47. client.login();
Advertisement
Add Comment
Please, Sign In to add comment