我正在制作一个机器人来促进我的 Discord 服务器上的内部笑话。它的意思是读取消息中最后一个单词的最后 2 个字母,如果它们以 er 结尾,它会响应“{last_word},我几乎不认识她!”我无法通过机器人回复任何消息。它的启动没有错误,机器人在 Repl.it 和我的测试不一致中显示为在线。
import discord
client = discord.Client(intents=discord.Intents.default())
@client.event
async def on_ready():
print('TARA_BOT ONLINE')
async def on_message(message):
if message.author == client.user:
return
words = message.content.split()
last_word = words[-1].lower() if words else ""
if last_word.endswith("er"):
response = f"{last_word} I hard know her"
await message.channel.send(response)
# Continue processing other commands
await client.process_commands(message)
client.run('Token')
如果您能在这里提供任何帮助,我们将不胜感激
当我在通用文本通道中写入消息时,机器人没有响应。我尝试了不同长度的短语来查看代码是否错误地读取了聊天内容
根据文档,
discord.Intents.default()
不包含message_content
意图,因此您的机器人将不会收到消息内容。您可以尝试以下方法:
intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)