创建邀请时记录 (discord.js)
Log when an invite is created (discord.js)
我正在尝试在创建邀请时进行记录,并希望将其应用于每个公会(这意味着每当在公会 a 中创建邀请时,它都会记录它。如果在公会 b 中创建公会,它只会记录它在该服务器中。)
我有问题,
问题:参考错误:未定义 maxAge
这是我的代码:
const Discord = require("discord.js");
let config = require("../config.json");
const { MessageEmbed } = require("discord.js");
const client = new Discord.Client();
module.exports = {
name: `printinvs`,
description: `Prints invites created.`,
async execute(message, args){
message.guild.fetchInvites()
.then
(invites => {
const printinvites = new Discord.MessageEmbed()
.setTitle(`Invite Information`)
.addField(`Max Age: ${maxAge}`)
.addField(`Max Uses: ${maxUses}`)
.addField(`Temporary: ${temporary}`)
.addField(`Invite URL: ${inviteurl}`)
.addField(`Invite created by: ${inviter}`)
.addField(`Channel: ${invite.channel}`)
.addField(`Time invited created: ${invite.createdAT}`)
.setColor(`RANDOM`)
message.client.channels.cache.get(channelid).send(printinvites);
})
}
}
出现此错误是因为您从未声明过最新的邀请,并且您在没有实际邀请的情况下使用其属性。
试试这个代码:
let config = require("../config.json");
const { MessageEmbed } = require("discord.js");
const client = new Discord.Client();
module.exports = {
name: `printinvs`,
description: `Prints invites created.`,
async execute(message, args){
message.guild.fetchInvites()
.then
(invites => {
let latestInvite = invites.last();
const printinvites = new Discord.MessageEmbed()
.setTitle(`Invite Information`)
.addField(`Max Age: ${latestInvite.maxAge}`)
.addField(`Max Uses: ${latestInvite.maxUses}`)
.addField(`Temporary: ${latestInvite.temporary}`)
.addField(`Invite URL: ${latestInvite.url}`)
.addField(`Invite created by: ${latestInvite.inviter}`)
.addField(`Channel: ${latestInvite.channel}`)
.addField(`Time invited created: ${latestInvite.createdAt}`)
.setColor(`RANDOM`)
message.client.channels.cache.get(channelid).send(printinvites);
})
}
}
我正在尝试在创建邀请时进行记录,并希望将其应用于每个公会(这意味着每当在公会 a 中创建邀请时,它都会记录它。如果在公会 b 中创建公会,它只会记录它在该服务器中。)
我有问题,
问题:参考错误:未定义 maxAge
这是我的代码:
const Discord = require("discord.js");
let config = require("../config.json");
const { MessageEmbed } = require("discord.js");
const client = new Discord.Client();
module.exports = {
name: `printinvs`,
description: `Prints invites created.`,
async execute(message, args){
message.guild.fetchInvites()
.then
(invites => {
const printinvites = new Discord.MessageEmbed()
.setTitle(`Invite Information`)
.addField(`Max Age: ${maxAge}`)
.addField(`Max Uses: ${maxUses}`)
.addField(`Temporary: ${temporary}`)
.addField(`Invite URL: ${inviteurl}`)
.addField(`Invite created by: ${inviter}`)
.addField(`Channel: ${invite.channel}`)
.addField(`Time invited created: ${invite.createdAT}`)
.setColor(`RANDOM`)
message.client.channels.cache.get(channelid).send(printinvites);
})
}
}
出现此错误是因为您从未声明过最新的邀请,并且您在没有实际邀请的情况下使用其属性。
试试这个代码:
let config = require("../config.json");
const { MessageEmbed } = require("discord.js");
const client = new Discord.Client();
module.exports = {
name: `printinvs`,
description: `Prints invites created.`,
async execute(message, args){
message.guild.fetchInvites()
.then
(invites => {
let latestInvite = invites.last();
const printinvites = new Discord.MessageEmbed()
.setTitle(`Invite Information`)
.addField(`Max Age: ${latestInvite.maxAge}`)
.addField(`Max Uses: ${latestInvite.maxUses}`)
.addField(`Temporary: ${latestInvite.temporary}`)
.addField(`Invite URL: ${latestInvite.url}`)
.addField(`Invite created by: ${latestInvite.inviter}`)
.addField(`Channel: ${latestInvite.channel}`)
.addField(`Time invited created: ${latestInvite.createdAt}`)
.setColor(`RANDOM`)
message.client.channels.cache.get(channelid).send(printinvites);
})
}
}