discord bot 仅在提及消息时才检测消息

Posted

技术标签:

【中文标题】discord bot 仅在提及消息时才检测消息【英文标题】:discord bot only detects messages when it is mentioned 【发布时间】:2020-11-22 02:31:45 【问题描述】:

我制作了一个不和谐的自我机器人,它应该检测每条发送的消息并随机响应。然而,当我把它放在一个有 450k 人的服务器上时,它只有在他们提到该帐户时才能检测到这些消息。这是代码

import os
import discord
import time
import random
import string
from discord.utils import get
from discord.ext import commands

TOKEN = "suwhgiowejvoifghoirwfofrgowegvofdgrovugdgovjfeogjrwo"

client=commands.Bot(command_prefix='', self_bot=True, fetch_offline_members=False)

@client.event
async def on_ready():
    print('connected to Discord!')
    
@client.event
async def on_message(message):
    print('message received')
    time.sleep(60)
    response=[
        'hi',
        'hello',
        'interesting',
        'no',
        'bruh',
        '.',
        'oof',
        'lol',
        'lmao',
        'yeah'
    ]
    try:
        await message.channel.send(random.choice(response))
        print('message sent')
    except:
        print("message error")
        pass

client.run(TOKEN, bot=False)

问题可能只是人太多,它不会起作用。但是,如果您认为这可能是其他问题,请告诉我。 (我知道 selfbots 违反 ToS 并且我的帐户可能会被禁止请不要生我的气)

【问题讨论】:

可能与self_bot有关。文档提到If True, the bot will only listen to commands invoked by itself rather than ignoring itself. If False (the default) then the bot will ignore itself. This cannot be changed once initialised. ~discordpy.readthedocs.io/en/latest/ext/commands/… time.sleep(60) 被阻塞,所以你应该使用 await asyncio.sleep(60) 【参考方案1】:

可能是fetch_offline_members=Falsetime.sleep(60),我想不出别的了

【讨论】:

以上是关于discord bot 仅在提及消息时才检测消息的主要内容,如果未能解决你的问题,请参考以下文章

discord.py bot:on_message 检测机器人等待发送()消息

Python discord bot如何将消息与列表进行比较

Discord Bot 删除特定频道中的消息

如何修复此 JDA discord bot 错误?

成功禁止某人时,Discord Bot 意外退出并出现错误

Discord Bot Python 提到