本文整理汇总了Python中discord.PCMVolumeTransformer方法的典型用法代码示例。如果您正苦于以下问题:Python discord.PCMVolumeTransformer方法的具体用法?Python discord.PCMVolumeTransformer怎么用?Python discord.PCMVolumeTransformer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类discord
的用法示例。
在下文中一共展示了discord.PCMVolumeTransformer方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: play_next_clip
# 需要导入模块: import discord [as 别名]
# 或者: from discord import PCMVolumeTransformer [as 别名]
def play_next_clip(self):
clip = self.next_clip()
try:
self.voice.play(discord.FFmpegPCMAudio(clip.audiopath), after=self.done_talking)
except discord.errors.ClientException as e:
if str(e) == "Not connected to voice.":
raise UserError("Error playing clip. Try doing `?resummon`.")
else:
raise
self.voice.source = discord.PCMVolumeTransformer(self.voice.source)
self.voice.source.volume = clip.volume
print("playing: " + clip.audiopath)
if self.last_clip != None and clip.audiopath != self.last_clip.audiopath:
remove_if_temp(self.last_clip.audiopath)
self.last_clip = clip
# try queueing an mp3 to play
示例2: on_ready
# 需要导入模块: import discord [as 别名]
# 或者: from discord import PCMVolumeTransformer [as 别名]
def on_ready():
await asyncio.sleep(1)
voice_channel = client.get_channel(int(voice_id))
while not client.is_closed():
vc = await voice_channel.connect()
vc.play(discord.FFmpegPCMAudio(filename))
vc.source = discord.PCMVolumeTransformer(vc.source)
vc.source.volume = 10.0
while vc.is_playing():
if sys.platform.startswith('linux'):
proc = psutil.Process(int(parentprocess))
if proc.status() == psutil.STATUS_ZOMBIE:
await client.logout()
sys.exit()
if not psutil.pid_exists(int(parentprocess)): # Parent is dead, Kill self :cry:
await client.logout()
sys.exit()
await asyncio.sleep(0.5)
await vc.disconnect(force=True)
示例3: jsk_vc_volume
# 需要导入模块: import discord [as 别名]
# 或者: from discord import PCMVolumeTransformer [as 别名]
def jsk_vc_volume(self, ctx: commands.Context, *, percentage: float):
"""
Adjusts the volume of an audio source if it is supported.
"""
if await playing_check(ctx):
return
volume = max(0.0, min(1.0, percentage / 100))
source = ctx.guild.voice_client.source
if not isinstance(source, discord.PCMVolumeTransformer):
return await ctx.send("This source doesn't support adjusting volume or "
"the interface to do so is not exposed.")
source.volume = volume
await ctx.send(f"Volume set to {volume * 100:.2f}%")
示例4: jsk_vc_play
# 需要导入模块: import discord [as 别名]
# 或者: from discord import PCMVolumeTransformer [as 别名]
def jsk_vc_play(self, ctx: commands.Context, *, uri: str):
"""
Plays audio direct from a URI.
Can be either a local file or an audio resource on the internet.
"""
if await connected_check(ctx):
return
voice = ctx.guild.voice_client
if voice.is_playing():
voice.stop()
# remove embed maskers if present
uri = uri.lstrip("<").rstrip(">")
voice.play(discord.PCMVolumeTransformer(discord.FFmpegPCMAudio(uri)))
await ctx.send(f"Playing in {voice.channel.name}.")
示例5: jsk_vc_youtube_dl
# 需要导入模块: import discord [as 别名]
# 或者: from discord import PCMVolumeTransformer [as 别名]
def jsk_vc_youtube_dl(self, ctx: commands.Context, *, url: str):
"""
Plays audio from youtube_dl-compatible sources.
"""
if await connected_check(ctx):
return
if not youtube_dl:
return await ctx.send("youtube_dl is not installed.")
voice = ctx.guild.voice_client
if voice.is_playing():
voice.stop()
# remove embed maskers if present
url = url.lstrip("<").rstrip(">")
voice.play(discord.PCMVolumeTransformer(BasicYouTubeDLSource(url)))
await ctx.send(f"Playing in {voice.channel.name}.")
示例6: play
# 需要导入模块: import discord [as 别名]
# 或者: from discord import PCMVolumeTransformer [as 别名]
def play(self, ctx, *, query):
"""Plays a file from the local filesystem"""
source = discord.PCMVolumeTransformer(discord.FFmpegPCMAudio(query))
ctx.voice_client.play(source, after=lambda e: print('Player error: %s' % e) if e else None)
await ctx.send('Now playing: {}'.format(query))
示例7: music_player_main
# 需要导入模块: import discord [as 别名]
# 或者: from discord import PCMVolumeTransformer [as 别名]
def music_player_main(voice_channel,server):
vc = await voice_channel.connect()
while True:
clear()
print(colored("Channel: {}".format(voice_channel.name),menucolour))
print()
print(colored("1. Play YouTube Link.",menucolour))
print(colored("2. Pause Player",menucolour))
print(colored("3. Resume Player",menucolour))
print(colored("4. Stop Player",menucolour))
print(colored("5. Volume Adjustment",menucolour))
print(colored("6. Disconnect",menucolour))
try:
player_choice = await loop.run_in_executor(ThreadPoolExecutor(), inputselection,'Option: ')
if int(player_choice) == 1:
clear()
url = await loop.run_in_executor(ThreadPoolExecutor(), inputselection,'YouTube Link to play: ')
try:
if os.path.isfile('RTBFiles/ServerSmasher/file.mp3'):
os.remove('RTBFiles/ServerSmasher/file.mp3')
print ("Removed old .mp3.")
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download([url])
vc.play(discord.FFmpegPCMAudio('RTBFiles/ServerSmasher/file.mp3'))
vc.source = discord.PCMVolumeTransformer(vc.source)
vc.source.volume = 1.0
except Exception as e:
await loop.run_in_executor(ThreadPoolExecutor(), inputselection, str(e))
elif int(player_choice) == 2:
vc.pause()
elif int(player_choice) == 3:
vc.resume()
elif int(player_choice) == 4:
vc.stop()
elif int(player_choice) == 5:
clear()
newvol = await loop.run_in_executor(ThreadPoolExecutor(), inputselection,'New Volume: ')
try:
vc.source.volume = float(int(newvol))
except Exception as e:
await loop.run_in_executor(ThreadPoolExecutor(), inputselection,e)
elif int(player_choice) == 6:
await vc.disconnect(force=True)
await music_player_channel_select(server)
except Exception as e:
continue