mirror of
https://github.com/nexy7574/LCC-bot.git
synced 2024-09-19 18:16:34 +01:00
handle timeout errors
This commit is contained in:
parent
2373a7b19c
commit
c52a908064
2 changed files with 17 additions and 8 deletions
4
.vscode/settings.json
vendored
Normal file
4
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"python.linting.pycodestyleEnabled": true,
|
||||||
|
"python.linting.enabled": true
|
||||||
|
}
|
|
@ -235,22 +235,28 @@ class Events(commands.Cog):
|
||||||
if message.author.voice is not None and message.author.voice.channel is not None:
|
if message.author.voice is not None and message.author.voice.channel is not None:
|
||||||
voice: discord.VoiceClient = None
|
voice: discord.VoiceClient = None
|
||||||
if message.guild.voice_client is not None:
|
if message.guild.voice_client is not None:
|
||||||
console.log("Disconnecting")
|
|
||||||
try:
|
try:
|
||||||
await _dc(message.guild.voice_client)
|
await _dc(message.guild.voice_client)
|
||||||
except discord.HTTPException:
|
except discord.HTTPException:
|
||||||
pass
|
pass
|
||||||
console.log("connecting")
|
try:
|
||||||
voice = await message.author.voice.channel.connect(timeout=10, reconnect=False)
|
voice = await message.author.voice.channel.connect(timeout=10, reconnect=False)
|
||||||
console.log("connected")
|
except asyncio.TimeoutError:
|
||||||
|
region = message.author.voice.channel.rtc_region
|
||||||
|
console.log(
|
||||||
|
"Timed out connecting to voice channel: {0.name} in {0.guild.name} "
|
||||||
|
"(region {1})".format(
|
||||||
|
message.author.voice.channel,
|
||||||
|
region.name if region else "auto (unknown)"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
if voice.channel != message.author.voice.channel:
|
if voice.channel != message.author.voice.channel:
|
||||||
console.log("moving")
|
|
||||||
await voice.move_to(message.author.voice.channel)
|
await voice.move_to(message.author.voice.channel)
|
||||||
|
|
||||||
if message.guild.me.voice.self_mute or message.guild.me.voice.mute:
|
if message.guild.me.voice.self_mute or message.guild.me.voice.mute:
|
||||||
await _dc(voice)
|
await _dc(voice)
|
||||||
console.log("disconnecting bad")
|
|
||||||
await message.channel.trigger_typing()
|
await message.channel.trigger_typing()
|
||||||
await message.reply("Unmute me >:(", file=discord.File(file))
|
await message.reply("Unmute me >:(", file=discord.File(file))
|
||||||
else:
|
else:
|
||||||
|
@ -263,9 +269,8 @@ class Events(commands.Cog):
|
||||||
if e is not None:
|
if e is not None:
|
||||||
console.log(f"Error playing audio: {e}")
|
console.log(f"Error playing audio: {e}")
|
||||||
|
|
||||||
console.log("sourcing")
|
|
||||||
src = discord.FFmpegPCMAudio(str(file.absolute()), stderr=subprocess.DEVNULL)
|
src = discord.FFmpegPCMAudio(str(file.absolute()), stderr=subprocess.DEVNULL)
|
||||||
console.log("Playing audio")
|
src = discord.PCMVolumeTransformer(src, volume=0.5)
|
||||||
voice.play(
|
voice.play(
|
||||||
src,
|
src,
|
||||||
after=after
|
after=after
|
||||||
|
|
Loading…
Reference in a new issue