【发布时间】: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