gpt4 book ai didi

python - 尝试使用 discord.py bot 在语音 channel 之间移动用户

转载 作者:行者123 更新时间:2023-12-04 15:21:26 25 4
gpt4 key购买 nike

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

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

我真的很喜欢编码,但我不是最擅长的。最近,我一直在尝试更好地使用 Python 来做一些真正对我有帮助的事情,而不是有趣的基于文本的游戏。我现在要做的是,我希望机器人在使用特定命令时将用户从一个语音 channel 移动到另一个语音 channel 。我一直在尝试在整个 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)

我也试过阅读文档,但我并不真正理解它们,因此以上内容只是我尝试从其他帖子/一些文档中尝试的内容。如果您确实有解决方案或可以帮助我,请发布!谢谢!

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

最佳答案

我有一个函数可以在我的 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 作为参数。您需要使用客户端提取相关数据进行操作。

关于python - 尝试使用 discord.py bot 在语音 channel 之间移动用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63200706/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com