【发布时间】:2021-09-12 07:33:51
【问题描述】:
@bot.event
async def on_message(message):
if message.author == bot.user:
return
if isinstance(message.channel, DMChannel):
guild = bot.get_guild(guildID)
channels = await guild.fetch_channels()
channel = discord.utils.get(channels, name=message.author.id)
message1 = message.author
embedVar = discord.Embed(title= f'{message.author} has sent a new message', description = message.content,
color= 0xff0000)
category = discord.utils.get(guild.categories, id = category.id)
channel = await guild.create_text_channel(message.author.id, category=category, id = message.author.id)
embedMod = discord.Embed(title = 'Information for the mods', description = '!close- Closes the text channel'
'\n!DM- To DM the user anonymously', color = 0x00FF00)
if channel not in channels:
await guild.create_text_channel(message.author.id, category = category)
await channel.send(embed=embedMod)
if channel in channels:
pass
await channel.send(embed=embedVar)
await bot.process_commands(message)
我正在制作一个机器人,用户通过 dms 向机器人寻求帮助,机器人在公会中创建一个特定类别下的文本频道。问题是每次向机器人发送消息时,机器人都会为每条消息创建一个文本通道,即使它是同一用户。如果机器人已经创建并且同一用户的其他消息已发送到该频道,我如何确保该机器人不会创建具有相同名称的文本频道..
【问题讨论】:
-
您需要将 user_id 和“his”channel_id 保存到 db 或 json 文件中。然后你可以检查用户是否已经有票
-
我该怎么做?你能帮助我吗? @古迪
-
循环遍历
catagory.channels并检查if channel.topic == str(message.author.id) -
它没有用,它仍在创建新频道。还有其他想法吗?
-
您可以使用当前代码编辑您的帖子吗? :D
标签: python discord.py