You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

discord.py创建ticket开头频道时无法触发消息发送的问题求助

问题分析与解决方案

核心问题1:事件名称错误

在discord.py v2.0及以上版本中,服务器内频道创建的触发事件是on_guild_channel_create,而原代码中的on_channel_create仅会响应DM频道的创建操作,这是代码无法识别ticket开头服务器频道创建的主要原因。

核心问题2:未启用必要的Intents权限

机器人需要获取服务器频道相关的事件通知,必须完成两步配置:

  1. 在Discord开发者后台的机器人页面,开启Server Members Intent和Guilds相关权限
  2. 在代码初始化Bot时指定启用对应Intents:
import discord
from discord.ext import commands

intents = discord.Intents.default()
intents.guilds = True
intents.guild_channels = True

bot = commands.Bot(command_prefix='你的前缀', intents=intents)

修正后的完整代码

import discord
from discord.ext import commands

intents = discord.Intents.default()
intents.guilds = True
intents.guild_channels = True

bot = commands.Bot(command_prefix='!', intents=intents)

@bot.event
async def on_guild_channel_create(channel):
    if channel.name.startswith('ticket'):
        embed = discord.Embed(title='Ticket Created', description='Thank you for creating a ticket.', color=0x00ff00)
        await channel.send(embed=embed)
        print(f'[$] Ticket Created at {channel.name}')

bot.run('你的机器人令牌')

额外验证项

  • 确认机器人在目标服务器拥有查看频道和发送消息的权限,否则即使事件触发也无法发送嵌入内容
  • 检查创建的频道确实是服务器内频道,而非DM频道

内容的提问来源于stack exchange,提问作者Aidan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 15:24:23