[英]discord.js V12 Send message to each guild owner from message
I want to send message to each owner of each guild of my bot.我想向我的机器人的每个行会的每个所有者发送消息。
To do that I have try this:为此,我尝试了这个:
/**
* @param {import('discord.js').Message} message
* @returns {Promise<void>}
*/
module.exports = async (message) => {
message.client.guilds.map((guild) =>{
message.client.users.fetch(guild.owner.id).then(u =>{
u.send('my awesome custom message')
})
})
}
But with this code I have this error:但是使用这段代码我有这个错误:
UnhandledPromiseRejectionWarning: TypeError: message.client.guilds.map is not a function
but when I console.logs message.client.guilds
I have an array of the guild... So I don't really know how I can parkour each guilds.但是当我 console.logs
message.client.guilds
时,我有一个公会数组......所以我真的不知道如何跑酷每个公会。 Also in my bot struct, I can access to client
by another that this way同样在我的机器人结构中,我可以通过这种方式通过另一个方式访问
client
On Discord.js v12, you need to add the cache
property.在 Discord.js v12 上,需要添加
cache
属性。 So it would be message.client.guilds.cache.map(...)
所以它将是
message.client.guilds.cache.map(...)
This amends your code to:这会将您的代码修改为:
/**
* @param {import('discord.js').Message} message
* @returns {Promise<void>}
*/
module.exports = async (message) => {
message.client.guilds.cache.map((guild) =>{
message.client.users.fetch(guild.owner).then(u =>{
u.send('my awesome custom message')
})
})
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.