Box Bunny with Fan Noises
DIAdiscord.js - Imagine an app
•Created by Box Bunny with Fan Noises on 7/9/2023 in #djs-voice
Trying to make a tts join command, getting invalid string format error
I'm currently trying to use a SlashCommandBuilder to make a command that will make the bot join the vc and begin reading messages, however I keep getting invalid string format when I try deploying the command
const { SlashCommandBuilder, ChannelType} = require('discord.js');
const { joinVoiceChannel, VoiceConnectionStatus, AudioPlayerStatus, VoiceConnection, getVoiceConnection, createAudioResource, createAudioPlayer, NoSubscriberBehavior} = require('@discordjs/voice')
module.exports = {
data: new SlashCommandBuilder()
.setName('TTSjoin')
.setDescription('Get discord bot to join the vc **WITH TTS**! (no leave command yet)')
.addChannelOption(option => option.setName('channel').setDescription('The channel to join').setRequired(true).addChannelTypes(ChannelType.GuildVoice)),
async execute(interaction) {
const channel = interaction.options.getChannel('channel');
const OwnerID = '686407266408464391'
let connectionjoin = getVoiceConnection(interaction.guild.id);
if(connectionjoin != undefined && interaction.user.id === OwnerID) {
let leaveconnection = getVoiceConnection(interaction.guild.id);
leaveconnection.destroy();
const player = createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Play,
},
});
const joinconnection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
});
await interaction.reply (`See you suckers, Box invited me to ${channel}!`)
voiceConnection=await entersState(voiceConnection, VoiceConnectionStatus.Connecting, 5_000);
const stream=discordTTS.getVoiceStream("hello text to speech world");
const audioResource=createAudioResource(stream, {inputType: StreamType.Arbitrary, inlineVolume:true});
if(voiceConnection.status===VoiceConnectionStatus.Connected){
voiceConnection.subscribe(audioPlayer);
audioPlayer.play(audioResource);
}
joinconnection.on('stateChange', (oldState, newState) => {
console.log(`Connection transitioned from ${oldState.status} to ${newState.status}`);
});
return;
}
else if(connectionjoin != undefined) {
await interaction.reply("I am in a vc!");
return;
}
const connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
});
voiceConnection=await entersState(voiceConnection, VoiceConnectionStatus.Connecting, 5_000);
const stream=discordTTS.getVoiceStream("hello text to speech world");
const audioResource=createAudioResource(stream, {inputType: StreamType.Arbitrary, inlineVolume:true});
if(voiceConnection.status===VoiceConnectionStatus.Connected){
voiceConnection.subscribe(audioPlayer);
audioPlayer.play(audioResource);
}
connection.on('stateChange', (oldState, newState) => {
console.log(`Connection transitioned from ${oldState.status} to ${newState.status}`);
});
console.log(getVoiceConnection)
await interaction.reply(`Joined ${channel}!`);
},
};
const { SlashCommandBuilder, ChannelType} = require('discord.js');
const { joinVoiceChannel, VoiceConnectionStatus, AudioPlayerStatus, VoiceConnection, getVoiceConnection, createAudioResource, createAudioPlayer, NoSubscriberBehavior} = require('@discordjs/voice')
module.exports = {
data: new SlashCommandBuilder()
.setName('TTSjoin')
.setDescription('Get discord bot to join the vc **WITH TTS**! (no leave command yet)')
.addChannelOption(option => option.setName('channel').setDescription('The channel to join').setRequired(true).addChannelTypes(ChannelType.GuildVoice)),
async execute(interaction) {
const channel = interaction.options.getChannel('channel');
const OwnerID = '686407266408464391'
let connectionjoin = getVoiceConnection(interaction.guild.id);
if(connectionjoin != undefined && interaction.user.id === OwnerID) {
let leaveconnection = getVoiceConnection(interaction.guild.id);
leaveconnection.destroy();
const player = createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Play,
},
});
const joinconnection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
});
await interaction.reply (`See you suckers, Box invited me to ${channel}!`)
voiceConnection=await entersState(voiceConnection, VoiceConnectionStatus.Connecting, 5_000);
const stream=discordTTS.getVoiceStream("hello text to speech world");
const audioResource=createAudioResource(stream, {inputType: StreamType.Arbitrary, inlineVolume:true});
if(voiceConnection.status===VoiceConnectionStatus.Connected){
voiceConnection.subscribe(audioPlayer);
audioPlayer.play(audioResource);
}
joinconnection.on('stateChange', (oldState, newState) => {
console.log(`Connection transitioned from ${oldState.status} to ${newState.status}`);
});
return;
}
else if(connectionjoin != undefined) {
await interaction.reply("I am in a vc!");
return;
}
const connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
});
voiceConnection=await entersState(voiceConnection, VoiceConnectionStatus.Connecting, 5_000);
const stream=discordTTS.getVoiceStream("hello text to speech world");
const audioResource=createAudioResource(stream, {inputType: StreamType.Arbitrary, inlineVolume:true});
if(voiceConnection.status===VoiceConnectionStatus.Connected){
voiceConnection.subscribe(audioPlayer);
audioPlayer.play(audioResource);
}
connection.on('stateChange', (oldState, newState) => {
console.log(`Connection transitioned from ${oldState.status} to ${newState.status}`);
});
console.log(getVoiceConnection)
await interaction.reply(`Joined ${channel}!`);
},
};
4 replies
DIAdiscord.js - Imagine an app
•Created by Box Bunny with Fan Noises on 7/9/2023 in #djs-voice
interaction.guild.members.me.voice.channel gives null response?
Tried grabbing the voice channel ID from where the bot was at, and I keep getting null or it won't change when the bot joins a new vc.
const { SlashCommandBuilder } = require('discord.js');
const { getVoiceConnection } = require('@discordjs/voice')
module.exports = {
data: new SlashCommandBuilder()
.setName('leave')
.setDescription('Get the discord bot to leave the vc it is currently in <>_<>'),
async execute(interaction) {
let connection = getVoiceConnection(interaction.guild.id);
if (connection === undefined) {
await interaction.reply("I am not in a vc!");
return;
};
const channel = interaction.guild.members.me.voice.channel
await interaction.reply({content: `Successfully left ${channel}`});
return connection.destroy()
},
};
const { SlashCommandBuilder } = require('discord.js');
const { getVoiceConnection } = require('@discordjs/voice')
module.exports = {
data: new SlashCommandBuilder()
.setName('leave')
.setDescription('Get the discord bot to leave the vc it is currently in <>_<>'),
async execute(interaction) {
let connection = getVoiceConnection(interaction.guild.id);
if (connection === undefined) {
await interaction.reply("I am not in a vc!");
return;
};
const channel = interaction.guild.members.me.voice.channel
await interaction.reply({content: `Successfully left ${channel}`});
return connection.destroy()
},
};
18 replies
DIAdiscord.js - Imagine an app
•Created by Box Bunny with Fan Noises on 7/8/2023 in #djs-voice
Creating a leave voice channel command for a bot
I have a working join command for discordjs v14, so now I'm trying to make a working disconnect command. code is here:
const { SlashCommandBuilder, ChannelType} = require('discord.js');
const { joinVoiceChannel, VoiceConnectionStatus, AudioPlayerStatus, VoiceConnection, getVoiceConnection, createAudioResource, createAudioPlayer} = require('@discordjs/voice')
module.exports = {
data: new SlashCommandBuilder()
.setName('leave')
.setDescription('Get the discord bot to leave the vc it is currently in <>_<>'),
async execute(interaction) {
const channel = interaction.options.getChannel('channel');
const connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
});
connection.destroy();
await interaction.reply(`successfully left ${channel}!`);
},
};
const { SlashCommandBuilder, ChannelType} = require('discord.js');
const { joinVoiceChannel, VoiceConnectionStatus, AudioPlayerStatus, VoiceConnection, getVoiceConnection, createAudioResource, createAudioPlayer} = require('@discordjs/voice')
module.exports = {
data: new SlashCommandBuilder()
.setName('leave')
.setDescription('Get the discord bot to leave the vc it is currently in <>_<>'),
async execute(interaction) {
const channel = interaction.options.getChannel('channel');
const connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
});
connection.destroy();
await interaction.reply(`successfully left ${channel}!`);
},
};
39 replies