【问题标题】:Complete discord bot say command [closed]完整的不和谐机器人说命令[关闭]
【发布时间】:2021-11-01 19:44:52
【问题描述】:

有人有完整的最新基本不和谐代码吗?或者任何愿意教我并指导我制作机器人的人。我很想为我的机器人做一个:'(

【问题讨论】:

  • 请编辑问题以将其限制为具有足够详细信息的特定问题,以确定适当的答案。

标签: discord discord.js bots


【解决方案1】:

Stackoverflow 不是代码编写服务,我们希望您在使用它时对 javascript/discord.js 了解最少,

虽然我会帮助你度过你的痛苦!欢迎来到 stackoverflow ?。

首先,我们需要 discord.js 并初始化 Client

const { Client, Intents } = require("discord.js");
const client = new Client({ intents: 4609 }); // This is intents bitfield value for DIRECT_MESSAGES, GUILD_MESSAGES and GUILD intents 

现在让我们为messageCreate 设置我们的事件监听器,这样我们就可以在用户消息时回复,同时我们将定义前缀、命令和用户参数

const { Client, Intents } = require("discord.js");
const client = new Client({ intents: 4609 });
const prefix = "!"; 
client.on("messageCreate" ,  (message) => {
const args = message.content.slice(prefix.length).trim().split(/+ /); // defining what are arguments ( eg. !say hello, hello is our argument ) 
const command = args.shift().toLowerCase();  // defining what a command is ( our first word to lowercase eg. !say hello then !say is our comamnd )
if(message.author.bot) return  // this is called botception, ignoring bot messages basically
if(command == "say") { // if the command is !say then repeat everything after the command 
message.reply(args.join(" ")); // eg. if user says !say hello welcome to stackoverflow, bot would reply with hello welcome to stackoverflow
message.delete(); // deleting the message from the user 
}
});
client.login("your_token_here");

这里有一些有用的资源可供初学者开始创建机器人!

Discord Developer Portal
Discord.js Beginners' Guide

【讨论】:

    猜你喜欢
    • 2018-07-21
    • 2018-11-10
    • 2017-05-31
    • 2020-09-01
    • 2021-10-21
    • 2022-01-15
    • 2021-06-17
    • 2020-11-07
    • 2020-11-10
    相关资源
    最近更新 更多