【问题标题】:How to detect if a user join in anyone of voice channel?如何检测用户是否加入任何语音频道?
【发布时间】:2021-10-22 13:49:02
【问题描述】:

我只是希望当特定用户在我的不和谐服务器上输入任何语音聊天时,我的机器人会检测到它然后进入语音并说“x 用户加入聊天或类似的东西”(我已经知道如何) .问题是如何检测用户进入? (检测必须是​​即时的)。 我尝试使用此代码:

@bot.event
async def on_voice_state_update(message, after, before, member):
ctx = await bot.get_context(message)
u = ctx.guild.get_member(428938023057620994)
for channel in ctx.guild.voice_channels:
    if sebastiano in channel:
        tts = gTTS(text=u + "in voice chat", lang='en')
        tts.save("u.mp3")
        try:
            vc = await channel.connect()
            await vc.play(discord.FFmpegPCMAudio('sebastiano.mp3'))
            await vc.disconnect()
        except:
            await ctx.send("Scusate ho la 104 e non funziono.")

但不起作用:

文件“/home/diego/Documents/Python 3/CancerBot/cancerbot.py”,第 26 行,on_voice_state_update ctx = 等待 bot.get_context(消息) 文件“/home/diego/.local/lib/python3.9/site-packages/discord/ext/commands/bot.py”,第 880 行,在 get_context 视图 = StringView(message.content) AttributeError:“成员”对象没有属性“内容”

【问题讨论】:

    标签: python-3.x discord.py


    【解决方案1】:

    这里有一些问题:

    on_voice_state_update 中没有消息或 ctx。

    参数必须为follow:

    member - 加入/离开/移动频道的会员

    before - 之前的语音状态。如果他进入了一个频道并且没有从一个频道移动到另一个频道,则频道属性将为无

    after - 之后的语音状态。如果他离开了频道并且没有移动频道,则频道属性将为无

    您回答您的问题以检查是否有人加入我也会这样做如果他搬家我会这样做:

    if after.channel:
    

    然后做你想做的事

    【讨论】:

      猜你喜欢
      • 2021-01-28
      • 2021-03-30
      • 2021-06-05
      • 2021-04-13
      • 1970-01-01
      • 2021-01-31
      • 1970-01-01
      • 2020-11-10
      • 2021-12-13
      相关资源
      最近更新 更多