【发布时间】: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)
标签: python-3.x discord.py