这是很新的。我一直在阅读discord.py的readthedocs API参考,它对我来说没有多大意义。到目前为止我有
import os
import discord
#os.environ['targetID']
bot = discord.Client()
intents = discord.Intents.default()
intents.members = True
channel_id = os.environ['channelID']
voice_channel = bot.get_channel(channel_id)
async def on_ready():
print ("Ready")
channel_id = os.environ['channelID']
voice_channel = bot.get_channel(channel_id)
await voice_channel.connect()
#async def on_voice_state_update(Member, channel[None], channel['general']):
# print(client.member.id)
#move_to(None)
bot.run(os.environ['token'])
我们的目标是让bot加入targetID
用户加入的语音频道,但我在让bot加入频道时遇到了麻烦
根据Nathan Marotte的回答,我将提供一个代码示例
您可以使用on_voice_state_update函数来检查成员所在的通道
因此,请查看以下代码:
解释代码中的不同功能:
before.channel is None
=检查用户是否不在频道中/不在频道中after.channel is not None
=检查用户加入的频道,然后授予角色member.id == targetID.id
=检查加入的member.id
是否与targetID.id
匹配on_voice_state_update是你需要的。当服务器上发生语音状态更改时,将调用此事件,包括
成员加入语音频道
成员离开语音频道
一个成员被他们自己的意愿压制或震耳欲聋
会员被公会管理员静音或耳聋
此函数接受3个参数,即发生更新的成员、之前的状态和之后的状态。 触发此事件时,请检查
member.id == target_member.id
。如果是这样,那么await after.channel.connect()
您还应该添加检查机器人是否已经在这个频道和其他东西,但这应该指向正确的方向
相关问题 更多 >
编程相关推荐