试图使我的不和谐机器人将用户移动到消息作者所在的语音通道。例如。我写!move @john
然后机器人将“约翰”移动到我的语音通道。
# command to move a user to current channel
@bot.command()
async def move(ctx,member:discord.Member=None):
channel= discord.utils.get(ctx.guild.voice_channels)
if not member:
await ctx.send("Who am I trying to move? Use !move @user")
await member.move_to(channel)
此时它会移动用户,但仅移动到服务器中的第一个语音通道。如何将其移至作者的语音通道?
作者所在的VoiceChannel
存储在ctx.author.voice.channel
中。值得注意的是,.voice
和.channel
可以是None
,所以我们需要检查一下
@bot.command()
async def move(ctx,member:discord.Member=None):
if ctx.author.voice and ctx.author.voice.channel:
channel = ctx.author.voice.channel
else:
await ctx.send("You are not connected to voice!")
if not member:
await ctx.send("Who am I trying to move? Use !move @user")
await member.move_to(channel)