In your on message event
client.on('message', async msg => {
msg.content = filter(msg.content)
let channelid1 = 'xxxx' //
let channelid2 = 'xx' //
if (msg.channel.id == channelid1 && msg.author.id != client.user.id) {
let attach = msg.attachments.array()
let test = getUrls(msg.content);
let arr = Array.from(test);
let emojiname = ''
if (msg.content.startsWith("<:uparrow:")) {
emojiname = 'uparrow'
} else if (msg.content.startsWith("<:downarrow:")) {
emojiname = 'downarrow'
}
let name = msg.guild.emojis.find(emoji => emoji.name == emojiname);
let embed = new Discord.RichEmbed()
.setDescription(msg.content)
.setColor('#A9A9A9')
if (name) {
start("Bot token xxxxx", 'Landing Discord channel ID xxx', embed, name)
} else {
start("Bot token xxxxx", 'Landing Discord channel ID xxx', embed)
}
if(arr.length > 0){
for(let i in arr){
start("Bot token xxxxx", 'Landing Discord channel ID xxx', arr[i])
}
}
if (attach.length > 0) {
start("Bot token xxxxx", 'Landing Discord channel ID xxx', attach[0].url)
}
client.login('Client token xxxx') //
}
You need to remove calling the login function
client.login('Client token xxxx')
as you don't want your bot re-logging in every time the event is fired.
start
method and yourclient.on("message", ... )
? Your code is creating a new client everytime it handles a message, which is unnecessary. – Gruntzy