【问题标题】:Python discord bot not respodingPython discord 机器人没有响应
【发布时间】:2023-02-10 20:04:51
【问题描述】:

我正在尝试制作一个不和谐的机器人,但该机器人没有响应我的任何命令,他在上网时正在编写命令,但仅此而已,我已授予他所有许可和所有意图,但什么也没有

import discord
import time

intents = discord.Intents.default()
intents.members = True
client = discord.Client(intents=intents)


# Dictionary to store the brake times for each user
brb_times = {}

@client.event
async def on_message(message):
    # Only process messages from other users, not the bot itself
    if message.author == client.user:
        return

    if message.content.startswith("!brb 5"):
        brb_times[message.author.name] = time.time() + 5 * 60
        await message.channel.send(f"{message.author.mention} has taken a 5-minute brake.")

    elif message.content.startswith("!brb 10"):
        brb_times[message.author.name] = time.time() + 10 * 60
        await message.channel.send(f"{message.author.mention} has taken a 10-minute brake.")

    elif message.content.startswith("!brb 15"):
        brb_times[message.author.name] = time.time() + 15 * 60
        await message.channel.send(f"{message.author.mention} has taken a 15-minute brake.")

    elif message.content.startswith("!back"):
        if message.author.name in brb_times:
            brake_time = brb_times[message.author.name]
            del brb_times[message.author.name]
            elapsed_time = time.time() - brake_time
            if elapsed_time > 0:
                await message.channel.send(f"{message.author.mention} is back, but was late by {int(elapsed_time)} seconds.")
            else:
                await message.channel.send(f"{message.author.mention} is back.")
        else:
            await message.channel.send(f"{message.author.mention} was not on a brake.")

@client.event
async def on_ready():
    print("Bot is ready!")
    await client.get_channel(CENSORED).send("Bot is ready to track breaks!")

client.run("CENSORED")

【问题讨论】:

  • 它是否输入了on_message?你尝试什么命令?
  • 不,它根本不进入 on_message。我已经尝试了所有方法,包括 !brb 5、!brb 10 和 !brb 15

标签: python discord bots


【解决方案1】:

您需要 message_content 成为 intents 中的 True

【讨论】:

    猜你喜欢
    • 2021-05-25
    • 2021-03-11
    • 2022-11-27
    • 2022-10-24
    • 2021-07-22
    • 2021-02-01
    • 2022-12-15
    • 2019-08-14
    相关资源
    最近更新 更多