【问题标题】:im making a discord bot for the first time in discord js and my test command wont work我第一次在 discord js 中制作一个 discord 机器人,我的测试命令无法正常工作
【发布时间】:2022-11-26 15:14:35
【问题描述】:

这是“我的代码”,命令不起作用。尝试按照 YouTube 教程进行操作。这是我第一次尝试做这样的事情。我所有的代码经验都来自简单的 python 代码。所以如果你有任何解释这个的视频,请发送

const { Client, GatewayIntentBits, EmbedBuilder, PermissionsBitField, Permissions, Message } = require(`discord.js`);

const prefix = '>';

const client = new Client({
    intents: [
        32767
    ]
});

client.on("ready", () => {
    console.log("botong is online!")

    client.user.setPresence({
        status: 'online',
        activity: {
            name: 'status',
            type: 'ActivityType.Playing'
        }
    });
});

client.on("messageCreate", (message) => {
    if (!message.content.startsWith(prefix) || message.author.bot) return;
    const args = message.content.slice(prefix.length).split(/ +/);

    //message array

    const messageArray = message.content.split(" ");
    const argument = messageArray.slice(1);
    const cmd = messageArray[0];

    //commands

    //test commands

    if (commands === 'test') {
        message.channel.send("Bot is working!")
    }

})

client.login("MY TOKEN");

试图运行它但没有任何反应,它应该在我的不和谐服务器中发送一条消息说“Bot is Working”

【问题讨论】:

    标签: javascript discord.js bots


    【解决方案1】:

    所以如果你有任何解释这个的视频,请发送

    这是来自 Codeacademy 的一篇文章,其中解释了如何创建一个简单的 Discord 机器人。 https://www.codecademy.com/article/christine_yang/build-a-discord-bot-with-node-js

    你的测试消息没有出现的原因:消息永远不会被发送,因为你没有定义commands所以它显然永远不会是'test'

    if (commands === 'test') {
    message.channel.send("Bot is working!")
    }
    

    编辑:这是文章中的代码示例,每当有人向频道发送“你好”时,它就会向频道发送消息。

    client.on('messageCreate', msg => {
    // You can view the msg object here with console.log(msg)
     if (msg.content === 'Hello') {
       msg.reply(`Hello ${msg.author.username}`);
     }
    });
    

    【讨论】:

      猜你喜欢
      • 2020-02-01
      • 2020-10-29
      • 2021-12-31
      • 2021-04-07
      • 2021-07-07
      • 2018-03-27
      • 2020-04-07
      • 2023-03-14
      • 2020-10-30
      相关资源
      最近更新 更多