aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar meooow25 <[email protected]>2018-10-17 12:38:32 +0530
committerGravatar meooow25 <[email protected]>2018-10-17 12:38:32 +0530
commitd019893bc598528730297bfb22ddc746e1c9734e (patch)
treed9b7f4c6ebf9600c57756909945399ef426f07ba
parentAdd cog to play spooky sounds (diff)
* Update channel ID.
* Add class docstring. * Make `disconnect` a helper static method.
-rw-r--r--bot/cogs/spookysound.py18
1 files changed, 12 insertions, 6 deletions
diff --git a/bot/cogs/spookysound.py b/bot/cogs/spookysound.py
index 99c1ae24..dd607097 100644
--- a/bot/cogs/spookysound.py
+++ b/bot/cogs/spookysound.py
@@ -4,10 +4,13 @@ from pathlib import Path
import discord
from discord.ext import commands
-HACKTOBERBOT_VOICE_CHANNEL_ID = 101010 # Replace with actual channel ID
+HACKTOBERBOT_VOICE_CHANNEL_ID = 498804789287714816
class SpookySound:
+ """
+ A cog that plays a spooky sound in a voice channel on command.
+ """
def __init__(self, bot):
self.bot = bot
@@ -25,14 +28,17 @@ class SpookySound:
once in 2 minutes.
"""
await ctx.send("Initiating spooky sound...")
- voice = await self.channel.connect()
file_path = random.choice(self.sound_files)
src = discord.FFmpegPCMAudio(str(file_path.resolve()))
+ voice = await self.channel.connect()
+ voice.play(src, after=lambda e: self.bot.loop.create_task(self.disconnect(voice)))
- async def disconnect():
- await voice.disconnect()
-
- voice.play(src, after=lambda e: self.bot.loop.create_task(disconnect()))
+ @staticmethod
+ async def disconnect(voice):
+ """
+ Helper method to disconnect a given voice client.
+ """
+ await voice.disconnect()
def setup(bot):