Discord.js V14中调用channel.send()时报Cannot read properties of undefined错误的排查求助
Discord.js V14中调用channel.send()时报Cannot read properties of undefined错误的排查求助
大家好,我现在在测试自己的Discord机器人功能,遇到了一个棘手的问题,想请各位大佬帮忙排查下。
我想要实现的功能是:当用户发送指令>send时,机器人会向指定的频道发送一条测试消息。我参考了Discord.js官方指南的写法写了代码,但运行时一直报错。
报错信息如下:
TypeError: Cannot read properties of undefined (reading 'send')
我已经反复核对过频道ID是正确的,但就是找不到问题所在。更奇怪的是,其他指令比如>test都能正常响应,唯独这个发送到指定频道的功能出问题。
以下是我的完整代码:
const { Events, EmbedBuilder, Client, GatewayIntentBits, } = require('discord.js'); const greeting = [ 'yo wsp', 'hi', 'hello muthafucka', 'stfu and talk with other people', ]; const lolo = greeting[Math.floor(Math.random() * greeting.length)]; const prefix = '>'; const client = new Client({ intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, ], }); const EmbedReply = { title: 'Do not ping this person.', description: ' 🙏 hes ded because of the pings already 🙏', color: '10038562', footer: { text: 'Current version: 0.0.1', icon_url: 'https://cdn.discordapp.com/attachments/1141734104543539220/1141750630763987015/pooperson.jpg', }, }; module.exports = { name: Events.MessageCreate, once: false, execute(msg) { if (msg.content === '<@1140642830302335098>') { msg.reply(`${lolo}`); } if (msg.content === '<@1089518964360609792>') { msg.reply({ content: `<@${msg.author.id}>`, embeds: [EmbedReply] }); } if (msg.content === prefix + 'test') { msg.reply('test succesful'); } if (msg.content === prefix + 'send') { const channel = client.channels.cache.get('1137720568850956300'); channel.send('test succes'); } }, };
麻烦各位帮忙看看问题出在哪,谢谢大家了!
备注:内容来源于stack exchange,提问作者average discord bot maker
相关产品推荐
相关产品推荐

