【问题标题】:Discord activity not working in sub command不和谐活动在子命令中不起作用
【发布时间】:2021-08-12 21:08:42
【问题描述】:

问题:
运行子命令时,机器人的状态不会更改。如果从index.js 运行更改状态,则可以正常工作。

预期输出:
更改机器人状态。

命令:

module.exports = {
    name: 'playing',
    description: 'playing status',
    guildOnly: true,
    args: true,
    devRole: true,
    usage: '<target>',
    execute(message, args) {
        message.channel.send(`Setting status to: ${args}`);
        client.user.setPresence({
            status: 'available',
            activity: {
                name: 'with ducks',
                type: 'PLAYING',
                url: 'https://discord.com'
            }
        });
    },
};

什么叫命令:

for (const file of commandFiles) {
    const command = require(`./commands/${file}`);
    client.commands.set(command.name, command);
}

【问题讨论】:

    标签: javascript node.js discord discord.js bots


    【解决方案1】:

    你没有提到错误是什么,我看不到你在哪里定义 client 变量,但似乎是导致错误的原因。

    message 有一个client 属性,您可以使用它来设置它的存在。所以,不要使用client,而是使用message.client

    execute(message, args) {
      message.channel.send(`Setting status to: ${args}`);
      message.client.user.setPresence({
        status: 'available',
        activity: {
            name: 'with ducks',
            type: 'PLAYING',
            url: 'https://discord.com'
        }
      });
    }
    

    【讨论】:

    • 即使在调试模式下我也没有收到任何错误。
    猜你喜欢
    • 2021-09-27
    • 2021-10-05
    • 1970-01-01
    • 2020-09-25
    • 2019-03-12
    • 2021-02-25
    • 2023-03-20
    • 1970-01-01
    • 2018-11-10
    相关资源
    最近更新 更多