我想知道公会成员何时登录,而不是成员何时加入,所以guildMemberAdd
在这种情况下不起作用。也许有另一种方法来实现我想做的事情,所以我将在这里解释。
当我的网站的用户升级到标准或专业会员时,他们可以加入我的discord服务器。我仍然需要弄清楚如何确定discord用户是我网站上的标准/专业订阅会员,但我认为我可以发送一个一次性邀请链接或一个会员必须输入的密码,在机器人发送欢迎消息询问密码或其他信息后发送discord机器人,但这应该是相对简单的。
我担心的是,在用户加入discord服务器后,如果该用户决定取消我网站上的standard/pro会员资格,我该怎么办?我现在想踢那个用户,所以我想我可以检测一个帮会成员何时在我的discord服务器上用bot启动会话,并测试该用户是否仍然是我网站上的标准/专业成员,但似乎没有任何事件。
也许我应该用另一种方式来考虑这个问题。有没有一种方法,只是踢成员从我的不和谐服务器之外的事件回调上下文??我今天早上才开始使用应用编程接口,所以如果我问的很简单,请原谅我。我从字面上可耻地只是复制/粘贴他们文档中的discord.js示例,看看简单的消息检测是否有效,谢天谢地确实如此(代码如下)
const Discord = require("discord.js")
const client = new Discord.Client()
client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}!`)
});
client.on("message", (msg) => {
if (msg.content === "ping") {
msg.reply("Pong!")
}
});
client.on("guildMemberAdd", (member) => {
member.send(
`Welcome on the server! Please be aware that we won't tolerate troll, spam or harassment.`
);
});
client.login(process.env.DISCORD_EVERBOT_TOKEN);
为了跟踪用户,我做了一个邀请过程,当我的网站成员升级到专业或标准帐户时开始。我找不到一种方法来确认用户连接实际上是与特定的邀请连接,以知道它是哪个用户,而不是发送临时的不和谐服务器密码。因此,我对机器人进行了编码,以提示新用户在触发guildMemberAdd
事件时将临时密码作为DM输入到机器人,该密码指向我网站上的用户,然后在此期间存储不和谐的成员ID事务,所以如果一个成员决定取消他们的订阅,我相应地删除角色。
下面的解决方案非常有效:
client.on("message", async (msg) => {
if(msg.author.id === client.user.id) { return; }
if(msg.channel.type == 'dm'){
try{
let user = await User.findOne({ discord_id: msg.member.id }).exec();
if(user)
await msg.reply("I know you are, but what am I?");
else {
user = await User.findOne({ discord_temp_pw: msg.content }).exec();
if(!user){
await msg.reply(`"${msg.content}" is not a valid password. Please make sure to enter the exact password without spaces.`)
}
else {
const role = user.subscription.status;
if(role === "Basic")
{
await msg.reply(`You have a ${role} membership and unfortunately that means you can't join either of the community channels. Please sign up for a Standard or Pro account to get involved in the discussion.
If you did in fact sign up for a Pro or Standard account, we're sorry for the mistake. Please contact us at info@mydomain.com so we can sort out what happened.`)
}
else{
const roleGranted = await memberGrantRole(msg.member.id, role);
const userId = user._id;
if(roleGranted){
let responseMsg = `Welcome to the team. With a ${role} membership you have access to `
if(role === "Pro")
await msg.reply(responseMsg + `both the Standard member channel and the and the Pro channel. Go and introduce yourself now!`);
else
await msg.reply(responseMsg + `the Standard member channel. Go and introduce yourself now!`);
}
else{
await msg.reply("Something went wrong. Please contact us at info@mydomain.com so we can sort out the problem.");
}
user = { discord_temp_pw: null, discord_id: msg.member.id };
await User.findByIdAndUpdate(
userId,
{ $set: user }
).exec();
}
}
}
}
catch(err){
console.log(err);
}
}
}
client.on("guildMemberAdd", (member) => {
member.send(
`Welcome to the server ${member.username}!
Please enter the password that you received in your email invitation below to continue.`
);
});
const memberGrantRole = async(member_id, role) => {
const guild = client.guilds.cache.get(process.env.DISCORD_SERVER_ID);
const member = guild.members.cache.get(member_id);
try{
await member.roles.add(role);
}
catch(err){
return {err, success: false};
}
return {err: null, success: true};
}
我试图做一个程序来创建一个无尽的循环,例如: 但是主要的问题是一个机器人听不到另一个机器人的声音,所以这不起作用。。。 有没有办法让机器人听另一个机器人的?提前感谢!:)
我要我的不和机器人发送彩色信息。 这是我的尝试: 对如何添加彩色文本到不和谐机器人有什么想法吗?我应该在开发人员不和中添加它吗?
我想知道是否有办法让我的discord机器人在播放youtube视频的音频后离开语音频道。我试着使用睡眠(视频的持续时间),但是为了获取和下载视频来播放,我使用了pafy,它给出了视频的持续时间,但是是00:00:00格式,它作为字符串而不是整数。我在=lamda e:await vc之后将代码更改为diconnect。断开连接,但它给我一个错误,在异步函数外面说“await”。我播放音乐的代码如
我有一个包含不和谐机器人代码的Python脚本。当我运行它时,它会激活不和谐机器人,并显示机器人的在线状态。但是,当我结束python脚本时,它会禁用bot。即使离线,我如何在不使用服务器的情况下保持机器人活动?
Bot只是不工作:/Bot没有给出任何错误
任何帮助都将不胜感激!