You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

discord.js监听message事件报错msg.replay不是函数该如何修复?

错误原因
  • 弃用警告:discord.js v13及更高版本已废弃message事件,需使用messageCreate事件替代,原message事件不会被触发,所以机器人收到消息无响应
  • 类型错误:属于拼写错误,消息对象的回复方法为reply(),你代码中误写为replay(),该方法不存在所以抛出错误
修复步骤
  1. 将事件监听的message替换为messageCreate
  2. 将msg.replay()修正为msg.reply(),同时传入需要回复的内容(reply方法不支持空调用,必须传内容参数)
修复后完整代码
import { Client, Intents } from 'discord.js';
 
export const bot = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
 
bot.on('ready', () => console.log(`${bot.user.username} is online`))
// 替换废弃的message事件
bot.on('messageCreate', async (msg) => {
    if (msg.author.bot) return;
    // 修正拼写错误,传入回复内容
    await msg.reply('你想要回复的消息内容')
});

提示:如果需要@触发消息的用户,直接使用msg.reply()即可,不需要额外拼接用户提及标签,方法会自动添加。

内容的提问来源于stack exchange,提问作者Vogel_YT

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.03 04:48:03