#Creating TTS Bot (Nearly completed)

1 messages · Page 1 of 1 (latest)

foggy iris
#
22:32:53 Audio #3    Connecting
22:32:53 Audio #3    Unknown OpCode (18)
22:32:53 Audio #3    Unknown OpCode (20)
22:32:53 Audio #3    Connected
Unhandled exception. System.IO.IOException: The process cannot access the file 'C:\Users\Sigening\RiderProjects\Dico-TTS\Dico-TTS\bin\Debug\net8.0\2024-05-12-22-33-05.mp3' because it is being used by another process.
   at System.IO.FileSystem.DeleteFile(String fullPath)
   at Dico_TTS.Modules.TtsModule.PlayTts(IGuildUser user, String msg) in C:\Users\Sigening\RiderProjects\Dico-TTS\Dico-TTS\Modules\TTSModule.cs:line 146
   at Dico_TTS.Modules.TtsModule.PlayTts(IGuildUser user, String msg) in C:\Users\Sigening\RiderProjects\Dico-TTS\Dico-TTS\Modules\TTSModule.cs:line 147
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_1(Object state)
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()
#
private async Task ClientOnUserVoiceStateUpdated(SocketUser user, SocketVoiceState prev, SocketVoiceState curr)
    {
        var botChannel = _client.GetGuild(Context.Guild.Id).CurrentUser.VoiceChannel;
        if (_isJoined && botChannel?.ConnectedUsers.Count == 1)
        {
            await botChannel.DisconnectAsync();
        }
        else if (user.Id == _client.CurrentUser.Id && prev.VoiceChannel != null && curr.VoiceChannel == null)
        {
            Console.WriteLine("Dispose Assets");
            _audioClient?.Dispose();
            if (_stream != null)
                await _stream.DisposeAsync();
            _isJoined = false;
        }
    }

I made this code to whenever bot was kicked out of a voice room or left itself, it should Dispose "IAudioService" and "AudioOutStream". and actually I don't konw what Dispose does here.

#

also, when it's "Joined", it should check if the bot's current Voice Channel has only one connect user, which is bot itself. and if it's alone inside, it should leave the current voice channel

#

I'm new to bot and assuming I should actually manage the _audioClient, _stream, _isJoined with Dictionary by the Guilds, but it's just for a single private server, so I think it's okay...

#

but...

#

by... mentioning this... I realized that...

#

actually it seems like it instantiates public class TtsModule : InteractionModuleBase<SocketInteractionContext> class for every commands?

#

because I have these

private static readonly Dictionary<ulong, string> SelectedVoice = new();
    private static readonly Dictionary<ulong, double> SelectedSpeed = new();

and they weren't static but after I realized that there's different instances every time I executed set_voice() command

#

I may not have read the documentation carefully, so I'm not sure 100% about everything I'm saying but I'll be back after making those variables static

#

but it seems like _isJoined is shared tho