【发布时间】:2018-01-13 11:49:17
【问题描述】:
我正在使用 discord.js 创建一个 Discord 机器人,我想创建一个可以清除消息的命令。现在,我有这段代码(只有有趣的部分),但我不知道为什么它不起作用:
// Importing discord.js, creating bot and setting the prefix
const Discord = require('discord.js');
const bot = new Discord.Client();
const prefix = "/";
// Array that stores all messages sent
messages = [];
bot.on('message', (message) => {
// Store the new message in the messages array
messages.push(message);
// Split the command so that "/clear all" becames args["clear", "all"]
var args = message.content.substring(prefix.length).split(" ");
// If the command is "/clear all"
if(args[0] == "clear" && args[1] == "all") {
bot.deleteMessages(messages); // Code that doesn't work
// Resets the array
messages = [];
}
}
// CONNECT !!!
bot.login('LOGING TOKEN HERE');
你能帮帮我吗?
【问题讨论】:
-
请创建尽可能小的代码来演示您的问题,然后发布。您现在发布的代码甚至没有平衡大括号,所以我无法判断您是否有任何导致问题的语法错误。
-
好的,我已经修好了@wmorrell!
标签: javascript bots discord discord.js