'TextChannel' 对象不可迭代 |通道检查不起作用

'TextChannel' object is not iterable | channel check not working

您好,我正在尝试检查频道是否已经存在,而不是在每次会员发送 modmail 请求时都创建一个新频道。我得到的错误是

File "C:\Users\User\Desktop\Build 1.0.2\cogs\modmail.py", line 145, in on_message
if get(modmailchannel, name=f"{message.author.name.lower()}{message.author.discriminator}"):
File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\utils.py", line 271, in get
for elem in iterable:
TypeError: 'TextChannel' object is not iterable
enter code here

不确定原因或方法不正确。创建的频道名称是用户名和鉴别符。我想要实现的是,如果该频道已经存在,请不要在同一频道中创建另一个 channel/post。

已申请帮助

这是我正在使用的代码:

@commands.Cog.listener()
async def on_message(self, message):
    if not isinstance(message.channel, discord.DMChannel) or message.author.id == self.bot.user.id:
        # not a DM, or it's just the bot itself
        return
    
    bucket = self._cd.get_bucket(message)
    retry_after = bucket.update_rate_limit()
    seconds = bucket.update_rate_limit()
    seconds = round(seconds, 2)
    hours, remainder = divmod(int(seconds), 3600)
    minutes, seconds = divmod(remainder, 60)
    if retry_after:
        pass
    else:
        channel = self.bot.get_channel(744311308509249610)
        if not channel:
            print("Mail channel not found! Reconfigure bot!")
        time = datetime.utcnow()
        guild = self.bot.get_guild(715288565877309521)
        member_role = get(guild.roles, name='Members')
        mod_role = get(guild.roles, name='Members')
        muted_role = get(guild.roles, name='Modmail Muted')
        user_id = message.author.id
        author = guild.get_member(user_id)
        
        content = message.clean_content
        
        if muted_role in author.roles:
            await message.channel.send("You're not allowed to use modmail.")
            return
        
        if len(message.content) < 0:
            await message.channel.send("Your message should be atleast 50 characters in length.")
            return
    
        if member_role in author.roles:
            emoji1 = ''
            emoji2 = '️'
            message_confirm = "You're about to send a message to the mod team, react with :incoming_envelope: to confirm otherwise :wastebasket: to discard your message."
            embed = discord.Embed(description=message_confirm, colour=0x5539cc)
            embed.title = "Confirm Message"
            confirm = await message.channel.send(embed=embed)
            await confirm.add_reaction(emoji1)
            await confirm.add_reaction(emoji2)
            check = reaction_check(message=confirm, author=message.author, emoji=(emoji1, emoji2))
            try:
                reaction, user = await self.bot.wait_for('reaction_add', timeout=60.0, check=check)
                if reaction.emoji == emoji1:
                    embed = discord.Embed(title=f"Message Sent", description=f"Hello {message.author.display_name}! We have received your message and we will get back to you as soon as possible. You can send another message in **{minutes}m {seconds}s**.", timestamp=time, colour=0x5539cc)
                    await message.channel.send(embed=embed)
                elif reaction.emoji == emoji2:
                    embed = discord.Embed(title=f"Message Not Sent", description=f"Your message has not been sent. You can send another message in **{minutes}m {seconds}s**.", timestamp=time, colour=0x5539cc)
                    await message.channel.send(embed=embed)
                    return
            except asyncio.TimeoutError:
                await message.channel.send(f'Sorry, you took too long to confirm your message. Try again in **{minutes}m {seconds}s**.')
                return
            overwrites = {
                guild.default_role: discord.PermissionOverwrite(read_messages=False),
                guild.me: discord.PermissionOverwrite(read_messages=True),
                member_role: discord.PermissionOverwrite(read_messages=False),
                mod_role: discord.PermissionOverwrite(read_messages=True)}
            
            embed = discord.Embed(title=f"Modmail message request from — {message.author.name}#{message.author.discriminator}", colour=0xff8100)
            embed.add_field(name="Member:", value=f"{message.author.mention}" ,inline=True)
            embed.add_field(name="Reply ID:", value=f"{message.author.id}" ,inline=True)
            embed.add_field(name="Message:", value=content[:1000] or "blank", inline=False)
            embed.set_footer(text=f"C&P Command: !reply {message.author.id}")
            if message.attachments:
                embed.add_field(name="Attachments", value=", ".join([i.url for i in message.attachments]))
            if len(content[1000:]) > 0:
                embed.add_field(name="Message (continued):", value=content[1000:])
            modmailchannel = await guild.create_text_channel(f'{message.author.name}{message.author.discriminator}', overwrites=overwrites, category=self.bot.get_channel(744944688271720518))
            await modmailchannel.send(embed=embed)
            
            if get(modmailchannel, name=f"{message.author.name.lower()}{message.author.discriminator}"):
                 await modmailchannel.send(embed=embed)
            
        else:
            await message.channel.send("Only members can use modmail.")

而不是 if get(modmailchannel, name=f"{message.author.name.lower()}{message.author.discriminator}"): 使用:

if modmailchannel.name == f"{message.author.name.lower()}{message.author.discriminator}":