Python 3.x 错误等待将继续创建多个通道,而不是检查
嗨,我遇到了一个问题,我的代码创建了多个通道。守则的功能应包括:Python 3.x 错误等待将继续创建多个通道,而不是检查,python-3.x,discord,discord.py,discord.py-rewrite,Python 3.x,Discord,Discord.py,Discord.py Rewrite,嗨,我遇到了一个问题,我的代码创建了多个通道。守则的功能应包括: 检查通道是否存在 如果频道确实存在,请不要创建新频道 否则,如果通道不存在,请创建一个通道 简而言之,它应该是如何工作的,在发送给机器人的直接消息中,on_message事件检查用户的响应,然后他们的消息被中继到已经存在的公会频道,否则在消息发送之前会创建一个新的公会频道 在这方面,问题是我无法通过检查通道是否存在来绕过它,它确实存在,但每次发送消息时它都会重复: 我尝试了这两种方法来检查: #Check 1 for chann
on_message
事件检查用户的响应,然后他们的消息被中继到已经存在的公会频道,否则在消息发送之前会创建一个新的公会频道
在这方面,问题是我无法通过检查通道是否存在来绕过它,它确实存在,但每次发送消息时它都会重复:
我尝试了这两种方法来检查:
#Check 1
for channel in guild.text_channels:
if channel.name == f"{message.author.name.lower()}{message.author.discriminator}" and channel.name is not None:
await channel.send(embed=embed)
else:
channel_non = await guild.create_text_channel(f'{message.author.name}{message.author.discriminator}', overwrites=overwrites, category=self.bot.get_channel(744944688271720518))
await channel_non.send(embed=embed)
#Check 2
channel_present = False
for channel in guild.text_channels:
if channel.name == f"{message.author.name.lower()}{message.author.discriminator}":
await channel.send(embed=embed)
channel_present = True
if channel_present:
channel_non = await guild.create_text_channel(f'{message.author.name}{message.author.discriminator}', overwrites=overwrites, category=self.bot.get_channel(744944688271720518))
await channel_non.send(embed=embed)
check 2代码导致
on_消息
事件不执行任何操作。非常感谢您的帮助,我不知道哪里出了问题。老实说,我只需要一个命令就可以了
@client.command()
async def command(ctx):
author = ctx.message.author
guild = ctx.guild
for channel in guild.text_channels:
if channel.name == ctx.message.author:
await channel.send(embed = embed)
return
channel = await guild.create_text_channel(f"{ctx.message.author}", overwrites = overwrites, category = self.bot.get_channel(744944688271720518))
await channel.send(embed = embed)
你不需要使用
guild=client.get\u guild(ctx.guild.id)
你可以说ctx.guild
,我已经提交了一个编辑,请检查一下。谢谢你。