Discord.js - 猫鼬狙击命令

时间:2021-04-11 15:47:20

标签: collections discord discord.js

我正在尝试使用命令处理程序执行狙击命令。 messageDelete 事件工作正常,但是当我使用 +snipe 时,我收到一个错误,提示我不能使用 .get。请帮帮我。

index.js

const fs = require('fs'); const Discord = require('discord.js'); const config = require('./config.json'); const mongoose = require('mongoose');

const client = new Discord.Client(); client.commands = new Discord.Collection();

mongoose.connect(mongoDB, { useNewUrlParser: true, useUnifiedTopology: true}).then(() => {
    console.log("Connecté a la base de donnée (MongoDB)");
}).catch((err) => {
    console.log("Un problème est survenu lors de la connexion a la base de donnée.. Error:"+err, "error");
})

//unnecessary things for my command handlers

client.snipes = new Discord.Collection();

client.login(config.token);

messageDelete 事件

const Discord = require('discord.js');

module.exports = async (client, message) => {
    if(message.author.bot) return;

    client.snipes.set(message.channel.id, {
    content: message.content,
    author: message.author.tag,
    member: message.member,
    image: message.attachments.first() ? message.attachments.first().proxyURL : null
    })
}

狙击命令

const Discord = require('discord.js')

module.exports = {
    name: 'snipe',
    execute(client, message) {
    const msg = client.snipes.find(message.channel.id)
    message.channel.send({embed: {
        color: 3447003,
        author: (msg.author, msg.member.user.displayAvatarURL()),
        description: (msg.content),
        date: new Date().toLocaleString("en-GB", {
            dataStyle: "full",
            timeStyle: "short",
          }),
    }})
    }
}

0 个答案:

没有答案