我不确定代码有问题,它似乎正在登录机器人,但它不会将消息发送到我请求的频道。我已经更新了开发人员门户上的权限,并在代码上建立了行会以及服务器中的权限。
它返回为: 特权消息内容意图缺失,命令可能无法按预期工作。
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')