const mudaeon = require('./mudaetime.json');
const cron = require('cron');
const Discord = require('discord.js');
const client = new Discord.Client();
module.exports = {
name: 'mudaetime',
description: '...',
execute(message, args) {
if (mudaeon) {
const channel = client.channels.cache.get('id');
let scheduledMessage = new cron.CronJob(
'* * * * *',
() => {
scheduledMessage.start();
},
message.react('✅'),
channel.send('check $tu ! <@&id')
);
} else !mudaeon;
{
cancel();
}
},
};
请帮助找出我的代码中的错误!我想做一个机器人,每十分钟在特定频道发送一条消息(尽管在这种情况下,我每分钟都放一次,这样我就可以看看它是否有效)
Please help find the error in my code! I wanted to make a bot that sends a message in a specific channel every ten minutes (although in this case, I put it for every minute so I can see if it works)
问题是你正在创建一个新的 Discord.Client() 实例,它不共享相同的频道、成员、角色等作为原作.您应该将原始的作为参数传递给您的 execute() 函数,而不是创建新的 Discord.Client().
The problem is that you are creating a new Discord.Client() instance, which does not share the same channels, members, roles, etc. as the original. Instead of creating a new Discord.Client(), you should pass the original one as an argument to your execute() function.
例如,您可以将 async execute(message, args){ 更改为 async execute(message, args, client){.然后,在您的命令处理程序中,将 command.execute(message, args) 更改为 command.execute(message, args, client)
For example, you could change async execute(message, args){ to async execute(message, args, client){. Then, in your command handler, change command.execute(message, args) to command.execute(message, args, client)
然而,还有一个更更简单的方法.client实际上是message对象的一个有效属性,指的是:
However, there is an even easier way. client is actually a valid property of the message object, referring to:
实例化消息的客户端
(Message#client代码> 文档)
所以,不要写:
const channel = client.channels.cache.get('id');
你可以写:
const channel = message.client.channels.cache.get('id')
它会完美运行!
这篇关于无法读取未定义的属性“发送"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
discord.js v12:我如何等待 DM 频道中的消息?discord.js v12: How do I await for messages in a DM channel?(discord.js v12:我如何等待 DM 频道中的消息?)
如何让我的机器人提及发出该机器人命令的人how to make my bot mention the person who gave that bot command(如何让我的机器人提及发出该机器人命令的人)
如何修复必须使用导入来加载 ES 模块 discord.jsHow to fix Must use import to load ES Module discord.js(如何修复必须使用导入来加载 ES 模块 discord.js)
如何列出来自特定服务器的所有成员?How to list all members from a specific server?(如何列出来自特定服务器的所有成员?)
Discord bot:修复“找不到 FFMPEG"Discord bot: Fix ‘FFMPEG not found’(Discord bot:修复“找不到 FFMPEG)
使用 discord.js 加入 discord 服务器时的欢迎消息Welcome message when joining discord Server using discord.js(使用 discord.js 加入 discord 服务器时的欢迎消息)