我想制作一个脚本,将消息发送到 disocrd 频道,以便(在我的例子中)创建一个游戏板。也就是说,通常当用户输入 /minesweeper 并单击 Enter 时,它将开始工作,但我使用discord.js-selfbot-v13制作了一个简单的脚本 它会向不和谐频道发送一条消息,但不会用斜杠 / 触发该命令。
const client = new Client()
const channelId = '1211807309307580430'
client.on('ready', async () => {
console.log(`${client.user.username} is ready!`)
const channel = client.channels.cache.get(channelId)
if (channel) {
channel.send('/minesweeper')
} else {
console.error('ERROR')
}
})
client.login(token)
要创建一个向 Discord 通道发送消息并使用斜杠 / 触发命令的脚本,您通常需要使用带有 Discord.js 等库的 Discord 机器人。自助机器人违反了 Discord 的服务条款,不应使用。
安装discord.js:
npm install discord.js
创建一个 JavaScript 文件(例如 bot.js)并向其中添加以下代码:
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
const PREFIX = '/';
client.once('ready', () => {
console.log('Bot is ready!');
});
client.on('messageCreate', async (message) => {
if (!message.content.startsWith(PREFIX) || message.author.bot) return;
const args = message.content.slice(PREFIX.length).trim().split(/ +/);
const command = args.shift().toLowerCase();
if (command === 'minesweeper') {
// Your code to create the game board here
message.channel.send('Minesweeper game board goes here...');
}
});
将“YOUR_TOKEN”替换为您的机器人令牌
client.login('YOUR_TOKEN');
将“YOUR_TOKEN”替换为您的 Discord 机器人的令牌。您可以通过在 Discord 开发者门户 (https://discord.com/developers/applications) 上创建机器人应用程序,然后将其添加到您的服务器来获取此令牌。
运行您的机器人脚本:
node bot.js
现在,当用户在您的机器人所在的频道中发送以 /minesweeper 开头的消息时,它将触发该命令并将消息发送回带有扫雷游戏板的频道(或您在命令中定义的任何其他操作) ).