【发布时间】:2021-05-23 21:29:28
【问题描述】:
我有一个奇怪的问题,我会尽力解释它,所以我们开始吧,
我正在使用 Python 编写一个 Discord 机器人。我做了一个只能在成员位于 discord.VoiceChannel 时执行的命令。它向频道发送消息并编辑语音频道:
事件:
@bot.command(name="lft", pass_context=True)
async def lft_command(ctx):
await lft.lft(ctx, bot)
第一种方法(lft):
async def lft(ctx, bot):
if ctx.channel == bot.get_channel(806109172336689162):
dcUser = ctx.author
if dcUser.voice is not None:
if dcUser.voice.channel.category == bot.get_channel(809430391177084969).category:
await methods.set_lft(dcUser, bot)
else:
await bot.get_channel(806112383693094942).send(
ctx.author.mention + ", you have to be in a temporary channel to use this command.",
delete_after=30)
else:
await bot.get_channel(806112383693094942).send(
ctx.author.mention + ", you have to be in a temporary channel to use this command.", delete_after=30)
else:
await bot.get_channel(806112383693094942).send(
ctx.author.mention + ", you can't use this command here, got to " + bot.get_channel(
806109172336689162).mention, delete_after=30)
第二种方法(set_lft):
async def set_lft(executor, bot):
channel = executor.voice.channel
lft_channel = bot.get_channel(806109172336689162)
user_role = await get_rank(executor)
print("b")
await channel.set_permissions(get(executor.guild.roles, id=806081402407092295), connect=False)
print("c")
await channel.edit(name="Looking for mates", user_limit=5)
msg = await lft_channel.send(
content=executor.mention + " is looking for teammates for ranked, he is " + user_role.name + ". Join a channel and react to the message to join the channel. There are currently " + str(
len(executor.voice.channel.members)) + "/5 player in the channel.",
delete_after=900)
await msg.add_reaction('✅')
lft_data[executor.id] = ["placeholder", msg, channel]
lft_data[msg.id] = [executor, "placeholder", channel]
lft_data[channel.id] = [executor, msg, "placeholder"]
如果执行该命令的成员离开语音通道,语音通道将再次变回正常语音通道:
async def set_casual(channel):
msg = get_msg(channel)
executor = get_executor(channel)
await msg.delete()
if len(channel.members) != 0:
await channel.set_permissions(get(executor.guild.roles, id=806081402407092295), connect=True)
await channel.edit(name=channel.members[0].nick + "'s channel", limit=None)
[lft_data.pop(x, None) for x in [msg.id, channel.id, executor.id]]
另一个用户可以执行该命令,但如果该命令被执行,它不会被调用或需要大约 5 分钟才能执行。是否有一个循环运行时间过长,或者根本没有停止?
提前谢谢你
【问题讨论】:
标签: python discord discord.py bots