尝试使用discord.py bot在语音频道之间移动用户

2024-09-28 22:37:26 发布

您现在位置:Python中文网/ 问答频道 /正文

对于任何有相同问题的人,您可以在下面查看所有评论,但这里是TD;DR:首先,我得到了我想要的频道并将其保存到一个变量中,然后我得到了消息的作者,最后我使用move_编码

async def moveplayer(ctx): channel = bot.get_channel(738705076557709392) member = ctx.message.author await member.move_to(channel)

我真的很喜欢编码,但我不是最好的。最近,我一直在尝试更好地使用python来做一些对我有实际帮助的事情,而不是有趣的基于文本的游戏。我现在要做的是,当使用特定命令时,我希望机器人将用户从一个语音频道移动到另一个语音频道。我一直试图在stackoverflow和互联网的其他地方找到解决方案,但我遇到的一切都不适合我。下面是一些我已经尝试过的东西。我也尝试过使用client = discord.Client()而不是bot = commands.Bot(command_prefix='hp!'),但似乎没有任何效果

@bot.command(name='moveme')
@commands.has_role('HpBotAccess')
async def moveplayer(*ctx,**message):
    voiceChannel = bot.get_channel(738704912912744450)
    await client.move_to(message.author, voiceChannel.id)
@bot.command(name='moveme')
@commands.has_role('HpBotAccess')
async def moveplayer(message):
    channel = discord.utils.find(lambda x: x.name == 'Vibin 3', message.server.channels)
    await client.move_member(message.author, channel)
@bot.command(name='moveme')
@commands.has_role('HpBotAccess')
async def moveplayer(message):
    await move_to(716193638433947690)

我也尝试过阅读这些文档,但我并不真正理解它们,因此上面的内容正是我在其他帖子/一小部分文档中尝试过的。如果你有一个解决方案或可以帮助我,请张贴它!谢谢大家!

另外,我意识到这个问题以前已经发布过了,但是其他帖子上的解决方案对我不起作用


Tags: namemessageasyncmovedefbotchannelawait
1条回答
网友
1楼 · 发布于 2024-09-28 22:37:26

我有一个在discord.py机器人上执行类似操作的函数。我想你的问题是你需要打电话给member.move_to(channel)。例如,我的机器人执行以下操作

channel = client.get_channel({channel ID here}) 
# channel now holds the channel you want to move people into

member = client.get_member({user_id of person to move})
#member now holds the user that you want to move

await member.move_to(channel)

您需要在member类上使用move_to,它将channel作为参数。您需要使用client来提取要操作的相关数据

相关问题 更多 >