我正在努力获取用户当前处于不和谐状态的语音频道的 ID(或名称)。 我希望能够将用户移至特定频道,但在一段时间后将用户移回其所在的频道。
所以基本上是一种“超时”方法。
我有代码,但 channelID 行不起作用。
# 2 "c.c" 2
# 1 "swap.h" 1
# 3 "c.c" 2
答案 0 :(得分:0)
您必须以不同的方式定义频道/可以以不同的方式请求它。
看看下面的代码:
@bot.command()
async def voice(ctx, member: discord.Member):
voice_state = None if not member.voice else member.voice.channel
if voice_state:
await ctx.send(f"Name: {voice_state} / ID: {voice_state.id}")
else:
await ctx.send("Not in a voice channel.")
我们做了什么?
member : discord.Member
作为需要的参数voice_state
定义为我们正在寻找的“渠道”voice_state
检查成员是否在语音频道中if/else
语句以处理 None
或实际通道如果您想以简单的方式使用它:
await ctx.send(f"{member.voice.channel}") # Gives out the name
await ctx.send(f"{member.voice.channel.id}") # Gives out the ID
注意,这可能只是回答你的问题,我没有用你的代码迁移它!