Discord工单状态机器人 - 代码不工作

0 投票
1 回答
31 浏览
提问于 2025-04-14 16:13

我对这段代码有点困惑,感觉它虽然能登录到机器人,但却无法把我想要的信息发送到指定的频道。我已经在开发者平台上更新了权限,也在代码中设置了公会(guild),还调整了服务器上的权限。

它返回的信息是:缺少特权消息内容的意图,命令可能无法按预期工作。

import discord
from discord.ext import commands
import datetime

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

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

ticket_channel_id = '1217573242009817138'
open_tickets_count = 5  

@bot.event
async def on_ready():
    print(f'Logged in as {bot.user}')

@bot.event
async def on_message(message):
    if message.channel.id == ticket_channel_id:
        # Assign the channel object to the channel variable
        channel = message.channel
        ticket_status = ''
        if open_tickets_count < 10:
            ticket_status = 'Low'
        elif 10 <= open_tickets_count <= 15:
            ticket_status = 'Moderate'
        else:
            ticket_status = 'Busy'

        now = datetime.datetime.now()
        day = now.weekday()  # 0 (Monday) to 6 (Sunday)
        hour = now.hour  # 0 to 23

        if 1 <= day <= 5:  # Monday to Friday
            if 9 <= hour < 17:
                response_time = 'Slow'
            elif hour < 21:
                response_time = 'Fast'
            else:
                response_time = 'Response unlikely until next day'
        elif day == 6:  # Saturday
            if hour < 10:
                response_time = 'Slow'
            elif hour < 18:
                response_time = 'Fast'
            elif hour < 21:
                response_time = 'Moderate'
            else:
                response_time = 'Unlikely response until next day'
        else:  # Sunday
            response_time = 'Responses unlikely'

        response_message = f'Ticket Status: {ticket_status}\nResponse Time: {response_time}'
        await channel.send(response_message)  # Use the channel variable to send the message


  
    try:
        await channel.send(response_message)
    except discord.HTTPException as e:
        print(f'Failed to send message: {e}')

bot.run('mybot-token')

1 个回答

1

试着添加这一行:

intents.message_content = True

来源:mousetail 对提问者的评论

撰写回答