我正在尝试为我的服务器制作一个不和谐的机器人,并为 modmail 创建一个频道。但是每次我尝试创建一个时,都会出现此错误。我正在使用 python 3.10
File "C:\Users\dyimi\Desktop\Code related stuff\python\discord..py\Palace Guard\cogs\modmail.py", line 35, in on_message
channel = await guild.create_text_channel(name=text_channel_name, overwrites=overwrites)
File "C:\Users\dyimi\Desktop\Code related stuff\python\discord..py\Palace Guard\venv\lib\site-packages\discord\guild.py",
line 948, in create_text_channel
data = await self._create_channel(name, overwrites, ChannelType.text, category, reason=reason, **options)
File "C:\Users\dyimi\Desktop\Code related stuff\python\discord..py\Palace Guard\venv\lib\site-packages\discord\guild.py",
line 844, in _create_channel
'id': target.id
AttributeError: 'str' object has no attribute 'id'
这是我的代码:
@commands.Cog.listener()
async def on_message(self, message):
if message.content.lower() in ["yes", "y", "ya", "yee", "ye", "no", "n", "nope"]:
return
if message.author == self.client.user:
return
def check(msg):
return msg.content.lower() in ["yes", "y", "ya", "yee", "ye"] and msg.author == message.author
if isinstance(message.channel, discord.channel.DMChannel):
await message.channel.send("Create ticket to modmail in Veemo's Kingdom? Yes or no.")
response = await self.client.wait_for("message", check=check)
if response:
guild = discord.utils.get(self.client.guilds, id=834666434042658816)
text_channel_name = message.author.name + "-" + message.author.discriminator
roles = guild.roles
overwrites = {
guild.default_role: discord.PermissionOverwrite(view_channel=False)
}
for role in roles:
if role.name not in mod_roles_list:
overwrites[role.name] = discord.PermissionOverwrite(view_channel=False)
channel = await guild.create_text_channel(name=text_channel_name, overwrites=overwrites)
else:
await message.channel.send("Ticket not created.")