私は簡単なボットを使って特定のチャンネルにユーザーの入力を再投稿しようとしています。私は数時間それに取り組んできたし、ここで立ち往生した。 bot.loginで予期しないトークンエラーが発生しました。修正するときに、削除した部分を戻すように求められます。私はボットにも一般的な質問があります。どのようにユーザーメッセージを変数として保存しますか?それを再印刷し、どのように確実にする必要があります!bot.loginの予期しないトークン/変数としてチャットを保存
コード:
const Discord = require("discord.js"); // use discord.js
var bot = new Discord.Client(); // sets Discord.Client to bot
const BOT_TOKEN = "hidden_here"
// bot's token
const PREFIX = "~" // bot's prefix
bot.on("ready", function() { // when the bot starts up, set its game to Use
*help and tell the console "Booted up!"
//bot.user.setGame("Use ~info") // sets the game the bot is playing
console.log("Bot is now online") // messages the console Bot is now online!
console.log("Use CTRL+C to shut down bot") // messages the console
});
bot.on("message", function(message) { // when a message is sent
if (message.author.equals(bot.user)) return; // if the message is sent by a
bot, ignore
if (!message.content.startsWith(PREFIX)) return; // if the message doesn't
contain PREFIX (*), then ignore
var args = message.content.substring(PREFIX.length).split(" "); // removes
the prefix from the message
var command = args[0].toLowerCase(); // sets the command to lowercase
(making it incase sensitive)
if (command == "say") { // creates command say
if (!message.member.roles.some(r=>["Votebot.Start"].includes(r.name)))
return message.reply("Sorry, you do not have the permission to do this!");
var sayMessage = message.content.substring(4)
message.delete().catch(O_o=>{});
message.channel.send(sayMessage);
}
if (command == "vote") { //creates command vote
if (!message.member.roles.some(r=>["Votebot.Start"].includes(r.name)))
return message.reply("Sorry, you do not have the permission to do this!");
message.channel.send("Type what you would like the vote to be about")
.then(() => {
var vote = message.channel.awaitMessages(response)
message.updateMessage("message", "Great! Starting a vote in #polls now")
message.channel.goto("#polls")
message.channel.send(vote)
message.react('✅');
message.react('❎');
});
bot.login(BOT_TOKEN); // connects to the bot
を、私はこのコードを実行しようとしましたが、それはそのメッセージが定義されていないというエラーを吐き出しています!私はdiscord.jsを再インストールしようとしましたが、動作しませんでした。 – Awsomebulderguy