英文:
How to make a discord.py event listener that deletes any new thread in a specific channel forum?
问题
我试图创建一个事件,用于监听在论坛中创建的新线程,并在不符合名称要求时删除它
我已经尝试过这个方法,它适用于所有论坛频道,但我找不到一种方法,只使其在一个特定的论坛中工作。问题出在这一行 if thread.channel.id == forum_channel_id:
上,它给我一个属性错误,说 Thread 对象没有 channel 属性。
@bot.event
async def on_thread_create(thread):
forum_channel_id = 1069778474815979570
if thread.channel.id == forum_channel_id:
return
if thread.name.startswith("Request #"):
async for entry in thread.guild.audit_logs(limit=1, action=discord.AuditLogAction.thread_create):
user = entry.user
break
embed = discord.Embed(title="Request Succesfully Done", description="The thread named '{}' was succesfully created.", color=discord.Color.green())
await user.send(embed=embed)
else:
async for entry in thread.guild.audit_logs(limit=1, action=discord.AuditLogAction.thread_create):
user = entry.user
break
embed = discord.Embed(title="Invalid Request", description="The thread named '{}' could not be created.", color=discord.Color.red())
await user.send(embed=embed)
await thread.delete()
有解决方法吗?
英文:
I'm trying to make an event that listens for a new thread created in a forum and deletes it if it doesn't match the name requisite
I've tried this, that works for every forum channels, but I can't find a way to make it working just for one specific forum. The problem is on the line if thread.channel.id == forum_channel_id:
that gives me an attribute error, saying that Thread object has no channel attribute
@bot.event
async def on_thread_create(thread):
forum_channel_id = 1069778474815979570
if thread.channel.id == forum_channel_id:
return
if thread.name.startswith("Request #"):
async for entry in thread.guild.audit_logs(limit=1, action=discord.AuditLogAction.thread_create):
user = entry.user
break
embed = discord.Embed(title="Request Succesfully Done", description="The thread named ''{}'' was succesfully created.".format(thread.name), color=discord.Color.green())
await user.send(embed = embed)
else:
async for entry in thread.guild.audit_logs(limit=1, action=discord.AuditLogAction.thread_create):
user = entry.user
break
embed = discord.Embed(title="Invalid Request", description="The thread named ''{}'' could not be created.".format(thread.name), color=discord.Color.red())
await user.send(embed = embed)
await thread.delete()
Any way to solve it?
答案1
得分: 0
...但在文件中,我也看不到它作为一个属性...
...但它 看起来 像是你真正想要的是该线程创建的原始 ID,这就是 Thread.parent_id
将为你提供的内容。
parent_id
该线程所属的父
TextChannel
或ForumChannel
的ID。
英文:
I mean, I don't see it in the documents either as an attribute...
...but it looks like what you really want is the origin ID of where the thread was created, which is what Thread.parent_id
will give you.
> parent_id
>
> The parent TextChannel
or ForumChannel
ID this thread belongs to.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论