本文整理汇总了Python中discord.VoiceChannel方法的典型用法代码示例。如果您正苦于以下问题:Python discord.VoiceChannel方法的具体用法?Python discord.VoiceChannel怎么用?Python discord.VoiceChannel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类discord
的用法示例。
在下文中一共展示了discord.VoiceChannel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: connect
# 需要导入模块: import discord [as 别名]
# 或者: from discord import VoiceChannel [as 别名]
def connect(self, channel):
if not isinstance(channel, discord.VoiceChannel):
channel = self.bot.get_channel(channel)
voice = self.voice
if voice is None:
print(f"attempting connect to: {channel.id}")
await channel.connect()
print(f"finished connect to: {channel.id}")
elif voice.channel and voice.channel.id == channel.id:
print(f"doin a disconnect and reconnect for: {channel.id}")
await voice.disconnect(force=True)
await asyncio.sleep(1)
await channel.connect()
print(f"finished reconnect for: {channel.id}")
# print(f"leaving this because we're supposedly already connected? ({channel.id})")
else:
print(f"attempting move to: {channel.id}")
await voice.move_to(channel)
print(f"finished move to: {channel.id}")
示例2: on_guild_channel_delete
# 需要导入模块: import discord [as 别名]
# 或者: from discord import VoiceChannel [as 别名]
def on_guild_channel_delete(self, channel: GUILD_CHANNEL) -> None:
"""Log channel delete event to mod log."""
if channel.guild.id != GuildConstant.id:
return
if isinstance(channel, discord.CategoryChannel):
title = "Category deleted"
elif isinstance(channel, discord.VoiceChannel):
title = "Voice channel deleted"
else:
title = "Text channel deleted"
if channel.category and not isinstance(channel, discord.CategoryChannel):
message = f"{channel.category}/{channel.name} (`{channel.id}`)"
else:
message = f"{channel.name} (`{channel.id}`)"
await self.send_log_message(
Icons.hash_red, Colours.soft_red,
title, message
)
示例3: on_guild_channel_create
# 需要导入模块: import discord [as 别名]
# 或者: from discord import VoiceChannel [as 别名]
def on_guild_channel_create(self, channel: GUILD_CHANNEL) -> None:
"""Log channel create event to mod log."""
if channel.guild.id != GuildConstant.id:
return
if isinstance(channel, discord.CategoryChannel):
title = "Category created"
message = f"{channel.name} (`{channel.id}`)"
elif isinstance(channel, discord.VoiceChannel):
title = "Voice channel created"
if channel.category:
message = f"{channel.category}/{channel.name} (`{channel.id}`)"
else:
message = f"{channel.name} (`{channel.id}`)"
else:
title = "Text channel created"
if channel.category:
message = f"{channel.category}/{channel.name} (`{channel.id}`)"
else:
message = f"{channel.name} (`{channel.id}`)"
await self.send_log_message(Icons.hash_green, Colours.soft_green, title, message)
示例4: convert
# 需要导入模块: import discord [as 别名]
# 或者: from discord import VoiceChannel [as 别名]
def convert(self, ctx, argument):
bot = ctx.bot
match = self._get_id_match(argument) or re.match(r'<#([0-9]+)>$', argument)
result = None
guild = ctx.guild
if match is None:
# not a mention
if guild:
result = discord.utils.get(guild.voice_channels, name=argument)
else:
def check(c):
return isinstance(c, discord.VoiceChannel) and c.name == argument
result = discord.utils.find(check, bot.get_all_channels())
else:
channel_id = int(match.group(1))
if guild:
result = guild.get_channel(channel_id)
else:
result = _get_from_guilds(bot, 'get_channel', channel_id)
if not isinstance(result, discord.VoiceChannel):
raise BadArgument('Channel "{}" not found.'.format(argument))
return result
示例5: mute
# 需要导入模块: import discord [as 别名]
# 或者: from discord import VoiceChannel [as 别名]
def mute(self, ctx, user: discord.Member, time: int=15):
'''Mute a member in the guild'''
secs = time * 60
for channel in ctx.guild.channels:
if isinstance(channel, discord.TextChannel):
await ctx.channel.set_permissions(user, send_messages=False)
elif isinstance(channel, discord.VoiceChannel):
await channel.set_permissions(user, connect=False)
await ctx.send(f"{user.mention} has been muted for {time} minutes.")
await asyncio.sleep(secs)
for channel in ctx.guild.channels:
if isinstance(channel, discord.TextChannel):
await ctx.channel.set_permissions(user, send_messages=None)
elif isinstance(channel, discord.VoiceChannel):
await channel.set_permissions(user, connect=None)
await ctx.send(f'{user.mention} has been unmuted from the guild.')
示例6: channel_bitrate
# 需要导入模块: import discord [as 别名]
# 或者: from discord import VoiceChannel [as 别名]
def channel_bitrate(
self, ctx: commands.Context, channel: discord.VoiceChannel, bitrate: int
) -> None:
"""Edit a voice channels bitrate"""
try:
await channel.edit(
bitrate=bitrate, reason=_("Requested by {author}").format(author=ctx.author)
)
except Exception:
await ctx.send(
_(
"`{bitrate}` is either too high or too low please "
"provide a number between 8000 and 96000."
).format(bitrate=bitrate)
)
return
await ctx.tick()
示例7: channel_userlimit
# 需要导入模块: import discord [as 别名]
# 或者: from discord import VoiceChannel [as 别名]
def channel_userlimit(
self, ctx: commands.Context, channel: discord.VoiceChannel, limit: int
) -> None:
"""Edit a voice channels user limit"""
try:
await channel.edit(
user_limit=limit, reason=_("Requested by {author}").format(author=ctx.author)
)
except Exception:
await ctx.send(
_(
"`{limit}` is either too high or too low please "
"provide a number between 0 and 99."
).format(limit=limit)
)
return
await ctx.tick()
示例8: convert
# 需要导入模块: import discord [as 别名]
# 或者: from discord import VoiceChannel [as 别名]
def convert(
self, ctx: commands.Context, argument: str
) -> Union[discord.TextChannel, discord.CategoryChannel, discord.VoiceChannel]:
match = self._get_id_match(argument) or re.match(r"<#([0-9]+)>$", argument)
result = None
guild = ctx.guild
if match is None:
# not a mention
result = discord.utils.get(guild.channels, name=argument)
else:
channel_id = int(match.group(1))
result = guild.get_channel(channel_id)
if not result:
raise BadArgument(f"Channel `{argument}` not found")
return result
示例9: ignore
# 需要导入模块: import discord [as 别名]
# 或者: from discord import VoiceChannel [as 别名]
def ignore(
self,
ctx: commands.Context,
channel: Union[discord.TextChannel, discord.CategoryChannel, discord.VoiceChannel],
) -> None:
"""
Ignore a channel from message delete/edit events and bot commands
`channel` the channel or category to ignore events in
"""
if ctx.guild.id not in self.settings:
self.settings[ctx.guild.id] = inv_settings
guild = ctx.message.guild
if channel is None:
channel = ctx.channel
cur_ignored = await self.config.guild(guild).ignored_channels()
if channel.id not in cur_ignored:
cur_ignored.append(channel.id)
await self.config.guild(guild).ignored_channels.set(cur_ignored)
self.settings[guild.id]["ignored_channels"] = cur_ignored
await ctx.send(_(" Now ignoring events in ") + channel.mention)
else:
await ctx.send(channel.mention + _(" is already being ignored."))
示例10: join
# 需要导入模块: import discord [as 别名]
# 或者: from discord import VoiceChannel [as 别名]
def join(self, ctx, *, channel: discord.VoiceChannel):
"""Joins a voice channel"""
if ctx.voice_client is not None:
return await ctx.voice_client.move_to(channel)
await channel.connect()
示例11: unmute
# 需要导入模块: import discord [as 别名]
# 或者: from discord import VoiceChannel [as 别名]
def unmute(self, ctx, user: discord.Member):
'''Unmute a member in the guild'''
for channel in ctx.guild.channels:
if isinstance(channel, discord.TextChannel):
await ctx.channel.set_permissions(user, send_messages=None)
elif isinstance(channel, discord.VoiceChannel):
await channel.set_permissions(user, connect=None)
await ctx.send(f'{user.mention} has been unmuted from the guild.')
示例12: init_channels
# 需要导入模块: import discord [as 别名]
# 或者: from discord import VoiceChannel [as 别名]
def init_channels(self):
await self.bot.wait_until_ready()
if self.configured.is_set():
return
for channel_id, settings in self.bot.config['logs'].items():
channel = self.bot.get_channel(channel_id)
if channel is None:
logger.warning(f'Configured logging channel ID {channel_id} was not found!')
if isinstance(channel, discord.VoiceChannel):
logger.warning(f'Voice channel {channel!r} was configured as a logging channel!')
continue
self.channels[channel] = settings
self.configured.set()
示例13: get_voice_client
# 需要导入模块: import discord [as 别名]
# 或者: from discord import VoiceChannel [as 别名]
def get_voice_client(self, channel: discord.abc.GuildChannel):
if isinstance(channel, discord.Object):
channel = self.get_channel(channel.id)
if not isinstance(channel, discord.VoiceChannel):
raise AttributeError('Channel passed must be a voice channel')
if channel.guild.voice_client:
return channel.guild.voice_client
else:
return await channel.connect(timeout=60, reconnect=True)
示例14: getperms
# 需要导入模块: import discord [as 别名]
# 或者: from discord import VoiceChannel [as 别名]
def getperms(self, member: discord.Member, channel: typing.Union[discord.TextChannel, discord.VoiceChannel, discord.CategoryChannel]):
perms = []
for perm, value in member.permissions_in(channel):
if value:
perms.append(perm)
return perms
示例15: jsk_vc_join
# 需要导入模块: import discord [as 别名]
# 或者: from discord import VoiceChannel [as 别名]
def jsk_vc_join(self, ctx: commands.Context, *,
destination: typing.Union[discord.VoiceChannel, discord.Member] = None):
"""
Joins a voice channel, or moves to it if already connected.
Passing a voice channel uses that voice channel.
Passing a member will use that member's current voice channel.
Passing nothing will use the author's voice channel.
"""
if await vc_check(ctx):
return
destination = destination or ctx.author
if isinstance(destination, discord.Member):
if destination.voice and destination.voice.channel:
destination = destination.voice.channel
else:
return await ctx.send("Member has no voice channel.")
voice = ctx.guild.voice_client
if voice:
await voice.move_to(destination)
else:
await destination.connect(reconnect=True)
await ctx.send(f"Connected to {destination.name}.")