[英]message event updating discord.js from v12 to v13
I have a discord bot, and I was using v12.我有一个不和谐的机器人,我使用的是 v12。 When the new v13 version came out, I tried to update my bot but it was too much for me.
当新的 v13 版本出来时,我试图更新我的机器人,但这对我来说太多了。 Now, I tried again and it went a little better.
现在,我又试了一次,结果好了一点。 Now at least it gets on, but doesn´t reply!
现在至少它开始了,但没有回复! When I execute the help command, it returns me this error:
当我执行帮助命令时,它返回这个错误:
TypeError: message.channel.startTyping is not a function
at Client.module.exports (/app/events/messageCreate.js:172:21)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
This is my bot.js
file:这是我的
bot.js
文件:
const { Client, Intents } = require('discord.js');
const Discord = require("discord.js");
const { I18n } = require("locale-parser");
const Mongoose = require("mongoose");
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
//client.errors = require("./modules/errors");
client.config = require("./config.json");
client.i18n = new I18n({ defaultLocale: "en" });
Mongoose.connect(client.config.mongo_uri, {
useNewUrlParser: true,
useUnifiedTopology: true
});
client.database = Mongoose.connection;
client.database.on("error", err => {
throw err;
});
client.database.once("open", async () => {
require("./models");
require("./handlers/eventHandler")(client);
require("./handlers/moduleHandler")(client);
client.login(process.env.BOT_TOKEN);
});
And this one, is app/events/messageCreate.js
:而这个,是
app/events/messageCreate.js
:
const Discord = require("discord.js");
const embeds = require("../modules/embeds.js");
const cooldown = {};
const Uses = require("../models/uses.js");
const Enmap = require("enmap");
const db = require("megadb"); //aca definimos db para lo que necesitemos mas adelante
let desactivadodb = new db.crearDB("ComandosDesactivados");
const fs = require("fs");
const guildModel = require("../models/guildModel");
var language = "";
module.exports = async message => {
try {
const bot = message.client;
const funcs = require("../modules/functions.js");
bot.color = funcs.color(message);
bot.lang = funcs.lang(message) || "en";
bot.langs = message.guild.language || language;
const msg = message;
if (msg.author.bot || !msg.guild) return;
let prefix = bot.config.prefixes[0];
let argsSlice = prefix.length;
if (!msg.content.toLowerCase().startsWith(prefix.toLowerCase())) {
let content = msg.content.trim();
let mention1 = "<@!" + bot.user.id + ">";
let mention2 = "<@" + bot.user.id + ">";
if (content == mention1 || content == mention2)
return embeds.mention(msg, prefix, bot);
if (content.startsWith(mention1)) argsSlice = mention1.length;
else if (content.startsWith(mention2)) argsSlice = mention2.length;
else return;
}
let args = msg.content
.slice(argsSlice)
.trim()
.split(/ +/g);
let command = args.shift().toLowerCase();
let cmdFile =
bot.commands.get(command) ||
bot.commands.find(
cmdFile => cmdFile.aliases && cmdFile.aliases.includes(command)
);
if (!cmdFile) return;
if (message.guild && !message.guild.language) {
let language = "en";
let guildDocument = await guildModel.findOne({
guildID: message.guild.id
});
if (guildDocument && guildDocument.language)
message.guild.language = guildDocument.language;
}
if (!message.guild) {
let language = "en"
};
if (cmdFile.guildOnly && !message.guild)
return await message.channel.send(
message.client.i18n.get(language, "errors", "command_guild_only")
);
if (
!cmdFile.enabled ||
desactivadodb.tiene(
`ComandosDesactivados_${command}_${message.guild.id}`,
`g${message.guild.id}`
)
)
return await message.channel.send(
message.client.i18n.get(
message.guild.language,
"errors",
"command_disabled"
)
);
if (
cmdFile.ownerOnly &&
!message.client.config.owners.includes(message.author.id)
)
return await message.channel.send(
message.client.i18n.get(
language,
"errors",
"command_owner_only",
{ command: cmdFile.name }
)
);
if (cmdFile.nsfwOnly && !message.channel.nsfw)
return await message.channel.send(
message.client.i18n.get(language, "errors", "nsfw_only", {
command: cmdFile.name
})
);
if (
cmdFile.permissions &&
!// message.client.config.owners.includes(message.author.id) ||
message.member.permissions.has(cmdFile.permissions || "ADMINISTRATOR")
)
return await message.channel.send(
message.client.i18n.get(
language,
"errors",
"not_enough_permission",
{ permissions: cmdFile.permissions.join(", ") }
)
);
if (
cmdFile.botpermissions &&
!message.guild.me.permissions.has(
cmdFile.botpermissions || "ADMINISTRATOR"
)
)
return await message.channel.send(
message.client.i18n.get(
language,
"errors",
"not_bot_enough_permission",
{ permissions: cmdFile.botpermissions.join(", ") }
)
);
let numuses = 1;
Uses.findOne(
{
command: cmdFile.name
},
(err, res) => {
if (err) console.log(err);
if (!res) {
const newDoc = new Uses({
command: cmdFile.name,
uses: 0
});
newDoc.save().catch(err => console.log(err));
} else {
res.uses = res.uses + numuses;
res.save().catch(err => console.log(err));
}
}
);
if (cmdFile.cooldown) {
if (!cooldown[msg.author.id]) cooldown[msg.author.id] = {};
let time = cooldown[msg.author.id][cmdFile.name] || 0;
if (time && time > Date.now()) {
let wait = ((time - Date.now()) / 1000).toFixed(2);
return message.channel.send(
message.client.i18n.get(
language,
"errors",
"wait_cooldown",
{ cooldown: wait, command: cmdFile.name }
)
);
}
cooldown[msg.author.id][cmdFile.name] =
Date.now() + cmdFile.cooldown * 1000;
}
message.channel.startTyping();
cmdFile.exec(bot, msg, args).then(message.channel.stopTyping());
} catch (err) {
console.error(err);
}
};
I just changed the Client
thing of the bot.js
, but I think I don´t understand the actual module.exports
and I am very sure that there is where the error is.我刚刚更改了
bot.js
的Client
bot.js
,但我想我不了解实际的module.exports
并且我非常确定错误所在。
In discord.js v13 TextChannel.startTyping()
method was replaced by TextChannel.sendTyping()
which you have to use now!在discord.js V13
TextChannel.startTyping()
方法改为TextChannel.sendTyping()
你必须现在就用! As moving to v13 guide says: "This method automatically stops typing after 10 seconds, or when a message is sent"!正如移动到 v13 指南所说:“此方法会在 10 秒后或发送消息时自动停止输入”!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.