TypeError:无法读取发送的属性(Discord.js)
Posted
技术标签:
【中文标题】TypeError:无法读取发送的属性(Discord.js)【英文标题】:TypeError: Cannot read property of send (Discord.js) 【发布时间】:2021-03-29 01:14:27 【问题描述】:我对@987654322@ 中的audit-logs
有疑问。我对 messageUptade 有疑问。这是我的代码表单messageUpdate
:
const Event = require('../structures/Event');
const MessageEmbed, Util: escapeMarkdown = require('discord.js');
const diffWordsWithSpace = require('diff');
const colors = require('../colors.json');
const stripIndents = require('common-tags');
module.exports = class extends Event
async run(message, old)
if (!message.guild || old.content === message.content || message.author.bot) return;
const logs = this.client.database.getLogs(message.guild.id);
const logsID = this.client.database.getLogsID(message.channel.id);
const logsCH = message.client.channels.cache.get(logsID);
if (!logs)
return;
else
const embed = new MessageEmbed()
.setColor(colors.orange)
.setAuthor(`Message Updated`)
.setTitle(old.author.tag, old.author.displayAvatarURL( dynamic: true ))
.setDescription(stripIndents`
**❯ Message ID:** $old.id
**❯ Channel:** $old.channel
**❯ Author:** $old.author.tag ($old.author.id)
`)
.setFooter(`$message.guild.name Logs`, message.guild.iconURL())
.setTimestamp()
.setURL(old.url)
.addField(`**❯ Updated Message Content:**`, diffWordsWithSpace(escapeMarkdown(old.content), escapeMarkdown(message.content))
.map(result => result.added ? `**$result.value**` : result.removed ? `~~$result.value~~` : `$result.value`)
.join(' '));
logsCH.send(embed);
;
这是数据库代码:
getLogs(id)
let query = 'SELECT * FROM logs WHERE guildid = ?';
const row = db.prepare(query).get(id);
if (row === undefined)
return;
else
return row;
getLogsID(id)
let query = 'SELECT channelid FROM logs WHERE guildid = ?';
const row = db.prepare(query).get(id);
if (row === undefined)
return;
else
return row.channelid;
我有TypeError: Cannot read property 'send' of undefined.
我们能帮帮我吗?
【问题讨论】:
【参考方案1】:找不到日志通道,因为您使用了message.client
而不是message.guild
这就是为什么它是undefined
。
您应该将获取频道的代码更改为:
const logsCH = message.guild.channels.cache.get(logsID);
【讨论】:
以上是关于TypeError:无法读取发送的属性(Discord.js)的主要内容,如果未能解决你的问题,请参考以下文章
discord.js TypeError:无法读取未定义的属性“发送”
Discord.js V12 TypeError:无法读取未定义的属性“发送”
TypeError:无法读取未定义 discord.js v12 的属性“发送”