如果我输入一些东西,bot不会发送任何东西,我会得到这个错误。
(node:1596) DeprecationWarning: The message event is deprecated. Use messageCreate instead
(Use `node --trace-deprecation ...` to show where the warning was created)
file:///C:/Users/name/Desktop/Projekte/Neo%201PG/src/bot.js:9
await msg.replay()
^
TypeError: msg.replay is not a function
代码:
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`))
bot.on('message', async (msg) => {
if (msg.author.bot) return;
await msg.replay()
});
这里有三个问题:
-
message
事件从Discord.JS v13开始被弃用,日志中有说明。您需要将其重命名为messageCreate
。 -
您将
reply
拼错为replay
。 -
msg.reply()
函数需要一个字符串作为参数传递。它不能与void形参一起使用。
你的messageCreate
事件应该是这样的:
bot.on('messageCreate', async (msg) => {
if (msg.author.bot) return;
await msg.reply('My message content!')
});