admin管理员组文章数量:1287114
I am trying to make my discord bot to print all the servers that it's connected to but when I try to run my code I get this type error:
TypeError: client.guilds.forEach is not a function
const Discord = require("discord.js")
const client = new Discord.Client()
client.on("ready", () => {
console.log("Conectat ca si: " + client.user.tag)
client.user.setActivity("my brother kiko jr", {type: "WATCHING"})
client.guilds.forEach((guild) => {
console.log(guild.name)
})
})
client.login("xyz")
I am trying to make my discord bot to print all the servers that it's connected to but when I try to run my code I get this type error:
TypeError: client.guilds.forEach is not a function
const Discord = require("discord.js")
const client = new Discord.Client()
client.on("ready", () => {
console.log("Conectat ca si: " + client.user.tag)
client.user.setActivity("my brother kiko jr", {type: "WATCHING"})
client.guilds.forEach((guild) => {
console.log(guild.name)
})
})
client.login("xyz")
Share
Improve this question
edited Apr 5, 2020 at 15:33
Danilo Ivanovic
1,2262 gold badges10 silver badges21 bronze badges
asked Apr 5, 2020 at 15:18
Raul UncRaul Unc
391 gold badge1 silver badge5 bronze badges
3
- I believe this question is already answered here. stackoverflow./questions/35969974/… – Danilo Ivanovic Commented Apr 5, 2020 at 15:32
- What version of Discord.js are you on? – Aci Commented Apr 5, 2020 at 15:48
- I looked at the answer you linked here but still couldn't solve it – Raul Unc Commented Apr 5, 2020 at 15:49
2 Answers
Reset to default 9I am assuming you're getting the error because you're using discord.js v12
If that is the case, your solution would be:
client.guilds.cache.forEach((guild) => {
console.log(guild.name);
});
no worries the problem ur facing right now is because you may have the version 12 of discord so i'd remend u to use the following code
client.guilds.cache.forEach((guild)=>{
console.log(guild.name)
})
or try re-installing discord with
npm i discord.js
and ur pc will install the version and u can start using it
本文标签: javascriptDiscord bot TypeError clientguildsforEach is not a functionStack Overflow
版权声明:本文标题:javascript - Discord bot TypeError: client.guilds.forEach is not a function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741252418a2366038.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论