我想创建一个 elo 排名机器人,用于不和谐,如下所示 有人可以告诉我如何做到这一点吗?我是编码新手,如果有人帮助我完成这个项目,我将非常感激。我的不和谐是 brrrrr444 请随时给我发短信,我不介意。谢谢!
我开发了一个不和谐机器人,我昨天在这个网站上发布了它,但我在设置它时一直遇到问题,所以如果有人有编码不和谐机器人的经验,请给我留言,我非常感谢你的帮助
这也是我尝试使用的代码
const Discord = require('discord.js');
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const client = new Discord.Client({
intents: [
Discord.GatewayIntentBits.Guilds,
Discord.GatewayIntentBits.GuildMessages
]
});
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}`);
});
const Enmap = require('enmap');
const prefix = '-'; // Change this to your desired prefix
const queues = new Enmap({ name: 'queues' });
const rankings = new Enmap({ name: 'rankings' });
client.on('messageCreate', async (message) => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
// Command to check rank
if (command === 'rank') {
const playerID = message.author.id;
const playerRank = rankings.get(playerID) || 0;
message.reply(`Your rank is ${playerRank}`);
}
// New command: Setup with -sett
if (command === '-sett') {
try {
const channel = await message.guild.channels.create('Queue', { type: 'GUILD_TEXT' });
const joinButton = new Discord.MessageButton()
.setCustomId('join_queue')
.setLabel('Join Queue')
.setStyle('PRIMARY');
const leaveButton = new Discord.MessageButton()
.setCustomId('leave_queue')
.setLabel('Leave Queue')
.setStyle('DANGER');
const row = new Discord.MessageActionRow()
.addComponents(joinButton, leaveButton);
const queueMessage = await channel.send({ content: 'Click a button to join or leave the queue:', components: [row] });
// Store queue message and channel id for future reference
queues.set('queue_message', queueMessage.id);
queues.set('queue_channel', channel.id);
// Inform setup completion
message.reply('Queue setup completed.');
} catch (err) {
console.error('Error during setup:', err);
message.reply('There was an error during setup.');
}
}
});
const YOUR_BOT_TOKEN = '';
const YOUR_APPLICATION_ID = '';
const YOUR_GUILD_ID = '';
client.login(YOUR_BOT_TOKEN);
const commands = [
{
name: 'sett',
description: 'Set up the queue system',
type: 1,
},
];
const rest = new REST({ version: '9' }).setToken(YOUR_BOT_TOKEN);
(async () => {
try {
console.log('Started refreshing application (/) commands.');
await rest.put(
Routes.applicationGuildCommands(YOUR_APPLICATION_ID, YOUR_GUILD_ID),
{ body: commands },
);
console.log('Successfully reloaded application (/) commands.');
} catch (error) {
console.error(error);
}})();
这个网站并不是真正的辅导网站。您需要学习如何自行创建机器人 - 但如果您发现遇到的具体问题,您可以在这里获得帮助。
为了学习创建 Discord 机器人,我建议遵循如下基本教程:https://www.youtube.com/watch?v=hoDLj0IzZMU
您还可以在 Discords 网站上找到信息:https://discordpy.readthedocs.io/en/stable/discord.html