【发布时间】:2020-12-14 04:21:30
【问题描述】:
我希望我的音乐机器人在加入频道时耳聋。但我仍然希望它播放音乐。我已经尝试过使用 await change_voice_state(*, channel, self_mute=False, self_deaf=False) 函数和 discord.py 文档,但没有任何帮助。我使用commands.command 方法。这是我的源代码的相关部分:
async def play(self, ctx, *, url):
"""Plays a song from a URL"""
client = ctx.guild.voice_client
state = self.get_state(ctx.guild) # get the guild's state
send_message = state.now_playing is not None
# connect to author's voice channel
if not client:
if ctx.author.voice is None:
raise commands.CommandError("You have to be in a voice channel.")
else:
channel = ctx.author.voice.channel
client = await channel.connect()
await channel.connect 似乎是相关部分。我希望我能在这里得到帮助。
我已经看到了其他可以使用的文档:
await voice_client.main_ws.voice_state(ctx.guild.id, channel.id, self_deaf=True)
但我收到以下错误消息:AttributeError: 'VoiceClient' object has no attribute 'main_ws'
我的代码如下所示:
if not client:
if ctx.author.voice is None:
raise commands.CommandError("Du musst in einem Sprachkanal sein, um dies zu tun.")
else:
channel = ctx.author.voice.channel
client = await channel.connect()
voice_client = ctx.guild.voice_client
channel = voice_client.channel
await voice_client.main_ws.voice_state(ctx.guild.id, channel.id, self_deaf=True)
也许我在某个地方犯了错误?
【问题讨论】:
-
@Sneftel 我看过这个。我几乎尝试了这里也写的所有内容。但是这是我所做的:
client = await channel.connect() , voice_client = ctx.guild.voice_client channel = voice_client.channel - await voice_client.main_ws.voice_state(ctx.guild.id, channel.id, self_deaf=True)这给了我以下错误:AttributeError: 'VoiceClient' object has no attribute 'main_ws'所以我必须将其更改为guild吗?
标签: discord discord.py