Cant get my random welcome messages to work in discord

I am trying to build my own discord bot which is pretty good fun, but having difficulty building my own little array to set up multiple welcome messages, so when someone joins, they will get one of those messages at random.

Here is my current code:

module.exports = ('guildMemberAdd', (member) => {
    const channel = member.guild.channels.cache.find(ch => ch.name === 'bot-testing');

    if (!channel) return;

    var messages = [
        "Welcome to Take My Sword '${member}', test 1",
        "Welcome to Take My Sword '${member}', test 2",
        "Welcome to Take My Sword '${member}', test 3",
        "Welcome to Take My Sword '${member}', test 4",
        "Welcome to Take My Sword '${member}', test 5"
    ];

    var messages = Math.floor(Math.random() * messages.length);
    
    channel.send(messageArray[rando]); 
});

And this is the error message, I am receiving:

/home/discord-bot/events/member/guildMemberAdd.js:2
        const channel = member.guild.channels.cache.find(ch => ch.name === 'bot-testing');
                                     ^

TypeError: Cannot read property 'channels' of undefined
    at module.exports (/home/discord-bot/events/member/guildMemberAdd.js:2:31)
    at Client.emit (events.js:315:20)
    at Object.module.exports [as GUILD_MEMBER_ADD] (/home/discord-bot/node_modules/discord.js/src/client/websocket/handlers/GUILD_MEMBER_ADD.js:16:14)
    at WebSocketManager.handlePacket (/home/discord-bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31)
    at WebSocketShard.onPacket (/home/discord-bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
    at WebSocketShard.onMessage (/home/discord-bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
    at WebSocket.onMessage (/home/discord-bot/node_modules/ws/lib/event-target.js:132:16)
    at WebSocket.emit (events.js:315:20)
    at Receiver.receiverOnMessage (/home/discord-bot/node_modules/ws/lib/websocket.js:825:20)
    at Receiver.emit (events.js:315:20)

My friend who has been helping me said to try change the 1st line, (member) to (client, member) and when I do, I just get this error message instead:

/home/discord-bot/events/member/guildMemberAdd.js:16
        channel.send(messageArray[rando]);
                     ^

ReferenceError: messageArray is not defined
    at module.exports (/home/discord-bot/events/member/guildMemberAdd.js:16:15)
    at Client.emit (events.js:315:20)
    at Object.module.exports [as GUILD_MEMBER_ADD] (/home/discord-bot/node_modules/discord.js/src/client/websocket/handlers/GUILD_MEMBER_ADD.js:16:14)
    at WebSocketManager.handlePacket (/home/discord-bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31)
    at WebSocketShard.onPacket (/home/discord-bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
    at WebSocketShard.onMessage (/home/discord-bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
    at WebSocket.onMessage (/home/discord-bot/node_modules/ws/lib/event-target.js:132:16)
    at WebSocket.emit (events.js:315:20)
    at Receiver.receiverOnMessage (/home/discord-bot/node_modules/ws/lib/websocket.js:825:20)
    at Receiver.emit (events.js:315:20)
[nodemon] app crashed - waiting for file changes before starting...

Understandably the array is probably coded wrong altogether, going off the errors but unfortunately I don’t have advanced knowlege to be able to fix it on my own so that is why I decided to ask here!

The bot can write/post to that room etc. that I am trying to do the test to so I know its not permissions, and I did have a single welcome message working perfectly fine, I just want to try an Array with multiple welcome messages, and on join they get a random one of how ever many I decide to make.

Any help would be really appreciated, even if its just a link to guide to better understand building arrays.

Kind Regards.

James.

188 thoughts on “Cant get my random welcome messages to work in discord”

  1. We’ve put jointly the most beneficial Instagram programs for your cГіmo poner blog personal en instagram:
    Editing shots. These apps allow for buyers to edit, resize and utilize filters.
    Format layout and style and design. These apps allow people to incorporate modern elements like collages, graphics, and also other graphics to your web site’s brand’s web page.

    Video clip tools. These purposes can increase the way in which your business captures and produces movies.
    Analytics engagement, details, and knowledge around the viewers. Down load Instagram apps to track how your audience interacts along with the efficiency of one’s content material.

    Desk of Contents for Instagram layout applicationsInstagram modifying applicationInstagram video editing applicationInstagram analytics appsApps for engagement on Instagram
    Bonus: fourteen time-preserving methods for Instagram impressive consumers Discover the tricks Hootsuite employs to supply leading-quality content material.

    Reply
  2. Here is the matter: It is really demanding to make a sizable pursuing on Instagram if you aren’t well known.

    There are several stuff you can do immediately to have at the very least 1,000 high quality Instagram followers for your Expert or personalized account. It all comes right down to where you need to devote your time and effort.

    So, can you connect a side blog to instagram will discuss a few methods that can assist you get People followers. These incorporate developing a worthy Instagram account, contests, and being accurate for your manufacturer.

    It is still essential to prioritize high-quality around amount

    It can be crucial not to target what number of followers you’ve but on the quality information you deliver. You can Normally mature your viewers in the event you make investments time and effort in generating informative and inspirational material, as an alternative to stressing about quick fixes to improve followers.

    It’s also wise to contemplate that the viewers dimensions will not have an affect on how many people comply with you. Your content is what keeps them next you.

    Possibly I was originally influenced by an influencer mainly because she had about 200K followers. This indicated to me that she was worthwhile next.

    On the other hand, this doesn’t mean that I have stopped subsequent influencers or brand names dependent on their dimensions audience. I’ve unfollowed quite a few mega-influencers and brands with thousands, Otherwise numerous followers simply because they have been no longer inspiring me.

    If you want to earn the extensive recreation of Instagram, you have to target Whatever you control. This consists of the standard and marketing within your information, as well as the brand you generate.

    Reply

Leave a Comment