English 中文(简体)
听闻
原标题:discord.js event handler welcome message

因此,我为我的不和谐的机器人开了一个活动手,这样,指数.js文档就子了。 但出于某种原因,当有人加入服务器时,我发出令人欢迎的信息。

这里我的活动手法:

const eventFiles = fs.readdirSync( ./events ).filter(file => file.endsWith( .js ));

for (const file of eventFiles) {
    const event = require(`./events/${file}`);
    if (event.once) {
        client.once(event.name, (...args) => event.execute(...args, Discord, client));
    } else {
        client.on(event.name, (...args) => event.execute(...args, Discord, client));
    }
}

而且 在我欢迎的致词中:

module.exports =  {
    name:  welcome ,
    once: false,
    execute(Discord, client) {

    const welcomechannelId =  753484351882133507  //Channel You Want to Send The Welcome Message
    const targetChannelId = `846341557992292362` //Channel For Rules

        client.on( guildMemberAdd , (member) => {
            let welcomeRole = member.guild.roles.cache.find(role => role.name ===  Umay );
            member.roles.add(welcomeRole);

            const channel = member.guild.channels.cache.get(welcomechannelId)

            const WelcomeEmbed = new Discord.MessageEmbed()
            .setTitle(`Welcome To ${member.guild.name}`)
            .setThumbnail(member.user.displayAvatarURL({dynamic: true, size: 512}))
            .setDescription(`Hello <@${member.user.id}>, Welcome to **${member.guild.name}**. Thanks For Joining Our Server.
Please Read ${member.guild.channels.cache.get(targetChannelId).toString()}, and assign yourself some roles at <#846341532520153088>. You can chat in <#753484351882133507> and talk with other people.`)
         // You Can Add More Fields If You Want
            .setFooter(`Welcome ${member.user.username}#${member.user.discriminator}`,member.user.displayAvatarURL({dynamic: true, size: 512}))
            .setColor( RANDOM )
        member.guild.channels.cache.get(welcomechannelId).send(WelcomeEmbed)
        
    })

    }
}

我没有错误,但是,如果有人加入服务器,他/她就没有被赋予作用,欢迎的信息就没有出现。 我把欢迎的信息编码放在一个事件上,即活动手正在处理。 谁能帮助?

最佳回答

The issue lies within the welcome code.

在手稿中,你有以下几行:

client.on(event.name, (...args) => event.execute(...args, Discord, client));

这使得客户在欢迎的法典中确定的名称财产。

You currently have it set to welcome, which is not a valid event. The bot is now listening for a welcome event, which will never happen.

第一项行动是将财产命名为<编码> 单号:<<0> 类似:

module.exports =  {
    name:  guildMemberAdd ,
//the rest of the code

Then you have another issue. Within the welcome code you have client.on() again.

否则永远不会奏效,除非有令人信服的幸运机会2人相互交织在一起,但即便如此,你只收到1份欢迎的信息。

摘录如下:

client.on( guildMemberAdd , (member) => {
//code
})

解决这个问题。

Then the last thing to do is having the member value being imported correctly. We do this by changing the following line:

execute(Discord, client) {

:

execute(member, Discord, client) {
//code

由此产生的法典将照此办理:

module.exports =  {
    name:  guildMemberAdd ,
    once: false,
    execute(member, Discord, client) {

    const welcomechannelId =  753484351882133507  //Channel You Want to Send The Welcome Message
    const targetChannelId = `846341557992292362` //Channel For Rules

            let welcomeRole = member.guild.roles.cache.find(role => role.name ===  Umay );
            member.roles.add(welcomeRole);

            const channel = member.guild.channels.cache.get(welcomechannelId)

            const WelcomeEmbed = new Discord.MessageEmbed()
            .setTitle(`Welcome To ${member.guild.name}`)
            .setThumbnail(member.user.displayAvatarURL({dynamic: true, size: 512}))
            .setDescription(`Hello <@${member.user.id}>, Welcome to **${member.guild.name}**. Thanks For Joining Our Server.
Please Read ${member.guild.channels.cache.get(targetChannelId).toString()}, and assign yourself some roles at <#846341532520153088>. You can chat in <#753484351882133507> and talk with other people.`)
         // You Can Add More Fields If You Want
            .setFooter(`Welcome ${member.user.username}#${member.user.discriminator}`,member.user.displayAvatarURL({dynamic: true, size: 512}))
            .setColor( RANDOM )
        member.guild.channels.cache.get(welcomechannelId).send(WelcomeEmbed)

    }
}

欢乐!

问题回答

tôi module.exports = { name: guildMemberAdd , async execute(member) { const welcomeRole = await member.guild.roles.cache.find(role => role.name === Thành Viên ); await member.roles.add(welcomeRole);

const welcomeChannel = await member.guild.channels.cache.find(channel => channel.name ===  welcome );
await welcomeChannel.fetch();
welcomeChannel.send(`Chào mừng ${member.user} đến với BRB Studio! Bạn là thành viên thứ ${member.guild.memberCount}, trước khi tham  gia server hãy đọc  ${member.guild.channels.cache.get(  ).toString()}. Một cuộc chiến tàn khốc đang chờ đón bạn`);
                    }
              }

//////////////////////////////// .setThumbnail() .setImage() 欢迎Channel.send(file = 不一致.File(12.png))

đây là mã lệnh của tôi, ai đó có thể giúp tôi thêm hình ảnh vào cngng lời chào không? tôi đang dùng JS V14





相关问题
Logic for Implementing a Dynamic Web Scraper in C#

I am looking to develop a Web scraper in C# window forms. What I am trying to accomplish is as follows: Get the URL from the user. Load the Web page in the IE UI control(embedded browser) in ...

Building a NetHack bot: is Bayesian Analysis a good strategy?

A friend of mine is beginning to build a NetHack bot (a bot that plays the Roguelike game: NetHack). There is a very good working bot for the similar game Angband, but it works partially because of ...

Updating a rss-feed continuously

I m creating a bot in PHP that continuously updates an RSS-feed and gathers information. Every loop takes around 0.1 sec but sometimes it takes up to 9 sec to finish the cycle. Why does this happen ...

ERROR occurs in Bots open source EDI Software

I developing a very big project in which we have to use a "Bots open source EDI tranlation tool." Bots uses a pythen script to convert a edi file to specified file (i.e. xml, csv, x12, database, etc)....

Is there a list of known web crawlers? [closed]

I m trying to get accurate download numbers for some files on a web server. I look at the user agents and some are clearly bots or web crawlers, but many for many I m not sure, they may or may not be ...

热门标签