await message sending may times over 问题
await message sending may times over issue
您好,我遇到了一个问题,我的机器人多次发送消息 await ctx.send(f":white_check_mark: Member(s) {member_names} kicked from voice channel.")
。这似乎发生在 await member.move_to(channel = None, reason=None)
假设如果有 4 个成员被踢出语音通道,它将发送 4 条消息。
有什么办法可以阻止这种情况发生。
这是我的代码:
async def voicekick(self, ctx, *members: discord.Member):
"""Kicks a member from voice and restricts them from joining all voice channels.
- member: The member to kick
"""
vcr = get(ctx.guild.roles, name="VC Restricted")
for member in members:
member_names = ', '.join([x.name for x in members])
if member.voice is None:
await ctx.send(f"Member(s) {member_names} not in a voice channel.")
else:
await member.move_to(channel = None, reason=None)
await member.add_roles(vcr)
await ctx.send(f":white_check_mark: Member(s) {member_names} kicked from voice channel.")
每当你踢一个成员时,将他们的名字添加到一个列表中,然后你可以在你踢完所有成员后显示这些名字:
async def voicekick(self, ctx, *members: discord.Member):
"""Kicks a member from voice and restricts them from joining all voice channels.
- member: The member to kick
"""
vcr = get(ctx.guild.roles, name="VC Restricted")
kicked_names = []
for member in members:
if member.voice is None:
await ctx.send(f"Member(s) {member_names} not in a voice channel.")
else:
await member.move_to(channel = None, reason=None)
await member.add_roles(vcr)
kicked_names.append(member.name)
kicked_names = ", ".join(kicked_names)
await ctx.send(f":white_check_mark: Member(s) {kicked_names} kicked from voice channel.")
您好,我遇到了一个问题,我的机器人多次发送消息 await ctx.send(f":white_check_mark: Member(s) {member_names} kicked from voice channel.")
。这似乎发生在 await member.move_to(channel = None, reason=None)
假设如果有 4 个成员被踢出语音通道,它将发送 4 条消息。
有什么办法可以阻止这种情况发生。
这是我的代码:
async def voicekick(self, ctx, *members: discord.Member):
"""Kicks a member from voice and restricts them from joining all voice channels.
- member: The member to kick
"""
vcr = get(ctx.guild.roles, name="VC Restricted")
for member in members:
member_names = ', '.join([x.name for x in members])
if member.voice is None:
await ctx.send(f"Member(s) {member_names} not in a voice channel.")
else:
await member.move_to(channel = None, reason=None)
await member.add_roles(vcr)
await ctx.send(f":white_check_mark: Member(s) {member_names} kicked from voice channel.")
每当你踢一个成员时,将他们的名字添加到一个列表中,然后你可以在你踢完所有成员后显示这些名字:
async def voicekick(self, ctx, *members: discord.Member):
"""Kicks a member from voice and restricts them from joining all voice channels.
- member: The member to kick
"""
vcr = get(ctx.guild.roles, name="VC Restricted")
kicked_names = []
for member in members:
if member.voice is None:
await ctx.send(f"Member(s) {member_names} not in a voice channel.")
else:
await member.move_to(channel = None, reason=None)
await member.add_roles(vcr)
kicked_names.append(member.name)
kicked_names = ", ".join(kicked_names)
await ctx.send(f":white_check_mark: Member(s) {kicked_names} kicked from voice channel.")