我刚刚开始使用 Javascript 和 Node.js,所以我真的不知道该怎么做。请对我有耐心。谢谢!
所以我在我的物理服务器上托管了一个 node.js。我想创建一个 Discord Bot,它在我的服务器上的特定时间发送每日消息,例如,我想每天早上 8 点向一个频道发送一条消息,说“早安”。我该怎么做?
目前,我只有这个代码来 ping 机器人(和服务器)
/*
A ping pong bot, whenever you send "ping", it replies "pong".
*/
// Import the discord.js module
const Discord = require('discord.js');
// Create an instance of a Discord client
const client = new Discord.Client();
// The token of your bot - https://discordapp.com/developers/applications/me
const token = 'your bot token here';
// The ready event is vital, it means that your bot will only start reacting to information …Run Code Online (Sandbox Code Playgroud) 因此,我很确定此代码在某一时刻可以正常工作,但是最近我注意到它有时起作用,但并非总是如此(阅读:它将始终清除n个消息,但可能不会清除其他成员) 。
因为我在教自己如何在该项目上使用多个文件,所以代码实际上是在两个文件之间划分的。我不确定这是否与问题有关。给定这两个文件的大小,我已将它们都上传到pastebin。
当我尝试清除n(其中n是可接受范围内的任何数字)时,它的清除效果很好,但是当我尝试通过用户名清除n时,我收到一条错误消息,指出
DiscordAPIError:无效的表单主体
限制:值“”不是int。
(注意这是两个双引号,格式有点不清楚)
我很困惑它在哪里获得不是int的值,因为我正在通过praseInt运行金额。我已经摘录了检查用户是否已定义的代码段,并将其发布在下面,因为我认为这是问题所在:
if (user) { // If User is Provided
debug.run(`Filtering messages by ${user.username}`);
const filterBy = user ? user.id : client.user.id;
messages = messages.filter(m => m.author.id === filterBy).array().slice(0, amount);
}
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激。如果我不知道,我或多或少将放弃该用户功能。
我也为格式化道歉。我永远无法掌握这种网站格式。
guildMemberAdd我正在制作一个 Discord 机器人,我正在使用这样的事件:
bot.on("guildMemberAdd", function(member) {
});
Run Code Online (Sandbox Code Playgroud)
如何检查是否member是机器人?
var server = message.guild;
for (var i = 0; i < server.channels.array().length; i++) {
server.channels.array()[i].delete();
}
server.createChannel("Text Channels", "category");
server.createChannel('general', "text");
Run Code Online (Sandbox Code Playgroud)
我正在尝试使文本通道“常规”进入“文本通道”类别
我找到的所有解决方案都取决于您知道类别ID。我想知道是否有一种方法可以获取类别ID,或者仅通过其名称将通用名称移入“文本通道”。
注意:目前,我正在考虑通过以下方式获取类别ID:
var categoryID = server.categories.find("name","Text Channels");
Run Code Online (Sandbox Code Playgroud)
然后使用
server.channels.find("name","general").setParent(categoryID);
Run Code Online (Sandbox Code Playgroud) 目前,我们正在使用入口点构建 Docker 映像,并将该映像传递到 Kubernetes 部署。
有没有办法将入口点直接动态传递给 Kubernetes,以便它启动 Spring Boot 应用程序?
在 Kubernetes 中直接传递此入口点有哪些不同方法?
### Runtime image ###
FROM openjdk:8-jre-alpine
#Set working dir
WORKDIR /test
# Copy the executable JAR
COPY /*.jar /test/
# Run the app
ENTRYPOINT java -Djava.security.egd=file:/dev/./urandom -Djsversion=1.0 -D<variable>=<service-1> -D<variable>=<service-2> -jar *.jar
Run Code Online (Sandbox Code Playgroud) docker spring-boot kubernetes kubernetes-deployment kubernetes-pod
如何存储我在NSUserDefaults中创建的Goal类型的对象数组?(快速)
这是代码:
func saveGoalList ( newGoalList : [Goal] ){
let updatedGoalList = newGoalList;
NSUserDefaults.standardUserDefaults().setObject(updatedGoalList, forKey: "GoalList")
NSUserDefaults.standardUserDefaults().synchronize()
}
class GoalsViewController: MainPageContentViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet var tableView: GoalsTableView!
var cell = GoalTableViewCell()
var goalsArray : Array<Goal> = [] //
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.delegate = self
self.tableView.dataSource = self
if var storedGoalList: [Goal] = NSUserDefaults.standardUserDefaults().objectForKey("GoalList") as? [Goal]{
goalsArray = storedGoalList;
}
var goal = Goal(title: "Walk the Dog")
goalsArray.append(goal)
saveGoalList(goalsArray)
self.tableView?.reloadData()
tableView.estimatedRowHeight = 44.0
tableView.rowHeight = UITableViewAutomaticDimension
self.xpnotificationView.alpha = …Run Code Online (Sandbox Code Playgroud) 我想从提及中获取用户ID。我正在执行用户信息命令,因此消息的作者不会总是他们,所以我不能这样做message.author.id。我已经使用子字符串将命令分为命令本身和提及内容,但是我无法将提及内容转换为ID。
我知道不和谐提及实际上是<@USERID>,这是获取ID的另一种方式。请告诉我是否可以删除<@>ID,让我留下ID,或者使用另一种方法将提及内容变成一个。我已经浏览了文档,但没有发现任何可以帮助我的东西。
我试图让机器人在特定时间写消息。例子:
const Discord = require("discord.js");
const client = new Discord.Client();
client.on("ready", () => {
console.log("Online!");
});
var now = new Date();
var hour = now.getUTCHours();
var minute = now.getUTCMinutes();
client.on("message", (message) => {
if (hour === 10 && minute === 30) {
client.channels.get("ChannelID").send("Hello World!");
}
});
Run Code Online (Sandbox Code Playgroud)
不幸的是,它只有在我触发另一个命令时才有效,例如:
if (message.content.startsWith("!ping")) {
message.channel.send("pong!");
}
Run Code Online (Sandbox Code Playgroud)
const Discord = require("discord.js");
const client = new Discord.Client();
client.on("ready", () => {
console.log("Online!");
});
var now = new Date();
var hour = now.getUTCHours();
var minute = now.getUTCMinutes(); …Run Code Online (Sandbox Code Playgroud) 是否可以使用 Jest 来验证不userId: 123应该存在的。
例如:
[
{ UserId: 112, Name: "Tom" },
{ UserId: 314, Name: "Paul" },
{ UserId: 515, Name: "Bill" }
]
Run Code Online (Sandbox Code Playgroud)
如果没有带有UserId: 123.
我想在两个输入元素之间添加一个前置元素。我可以用额外的 css 解决它,但这不是我想要的。
是否有仅使用bootstrap而没有额外 css代码的解决方案?
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<div class="input-group input-group-sm m-4 w-50">
<input class="form-control" type="text">
<div class="input-group-prepend">
<div class="input-group-text">@</div>
</div>
<input class="form-control"></input>
</div>Run Code Online (Sandbox Code Playgroud)
discord.js ×6
javascript ×6
node.js ×3
discord ×2
bootstrap-4 ×1
categories ×1
channel ×1
css ×1
docker ×1
ios ×1
jestjs ×1
kubernetes ×1
move ×1
spring-boot ×1
swift ×1