例如,当 user1 连接到 vc1 时,“hello user1”在文本通道通用中发送,但当用户 2 连接到 vc1 时,“hi user2”在文本通道通用中发送
我是使用 discord.py 和 python 编码的新手,一般来说,最简单的方法是什么 以下是我迄今为止尝试过的示例
@client.event
async def on_voice_state_update(member, before, after):
print(member)
vc = client.get_channel(id=channel id number)
vc1 = vc.members
if member in vc1[0] == "User#1234":
send msg in general text channel
答案 0 :(得分:1)
从角度来看,您的活动构建得很好,但多一点结构会更好,而且有些地方完全错误。
看看下面的代码:
@client.event
async def on_voice_state_update(member, before, after):
channel = before.channel or after.channel
if channel.id == VoiceChannelID: # Insert voice channel ID
if before.channel is None and after.channel is not None: # Member joins the defined channel
channel1 = client.get_channel(GeneralTextChatID) # Define the general channel
await channel1.send(f"Welcome to the voice channel {member.mention}!") # Mention the member
我们做了什么?
channel=
)f-string
提及该成员