discord.js

Create Channel Switch Logger

大憨熊 提交于 2019-12-14 00:07:42
问题 I'm trying to create a channel switch logger which allows me to specify a channel where the messages get posted. So, for example, I create a TextChannel called "Channel Switches". When now a user changes voice channel, it should appear a message in this Channel. (eg. <USER> left channel <CHANNEL> and joined <CHANNEL>. ) MY PROBLEM IS: I get no errors and the Bot is not responding... Here my first try: var Discord = require('discord.js'); var logger = require("winston"); var auth = require(".

Stop loop in discord.js

╄→尐↘猪︶ㄣ 提交于 2019-12-13 23:05:00
问题 I need help to stop a loop in discord.js. I don't know what to do to stop the loop. let sec = 5; let timer = setInterval(function() { if (command = "8") message.channel.send("ddd"); }, sec * 1000); if (command = "stoploop") clearInterval(timer); My problem is that clearInterval is not defined. 回答1: In if (condition) statements, you can't use = . This is used to assign a new value to a variable, property or anything else. The is equal to selectors are: == for equal to. === for equal to of the

How to create a text channel

旧巷老猫 提交于 2019-12-13 18:18:37
问题 Recently I have been making a discord bot, and I wanted to make a channel once the players have entered the command >report [Tag] [Reason] . Here are the two methods I have tried (one from a previous StackOverflow question that did not work for me): function makeChannel(message){ var server = message.guild; var name = message.author.username; server.createChannel(name, "text"); } Then I tried my own version to see if I could do it: var name = message.author.username; let reportchannel =

How to get snekfetch results into an object?

我怕爱的太早我们不能终老 提交于 2019-12-13 18:14:40
问题 I'm writing a discord.js bot and trying to call a weather API using Node.js / snekfetch. The issue is I can't figure out how to just put the data returned from the API into a javascript object. I want to do something like this: let [country, ...city] = args; let url = `http://api.openweathermap.org/data/2.5/forecast?q=${city},${country}&units=metric&APPID=${config.weatherID};`; var weatherObject; snekfetch.get(url).then(r => weatherObject = r.body);` but obviously this doesn't work so what am

Can not use startsWith Discord.js question

☆樱花仙子☆ 提交于 2019-12-13 10:28:41
问题 this is my role command. I'm trying to use startsWith to give roles: if the arg's first letters are the same as the role, it should be assigned to the user. exports.run = async function (msg,args) { if(!msg.member.hasPermission('MANAGE_ROLES')) return; const member = msg.mentions.members.first(); const name = msg.mentions.users.size ? args.replace(/ +/, ' ').split(' ')[1] : args; const role = msg.guild.roles.find(r => r.name.toLowerCase().startsWith(name.toLowerCase())); if (name && !role

How to tag users?

孤者浪人 提交于 2019-12-13 09:55:43
问题 I am looking to create a command in order to tag certain users. This is what I have tried: var players = [ "@RYAN#9602" ] switch(args[0].toLowerCase()){ case "play": message.channel.send(players.join('\n')); break; } However, it just sends a message into the text channel without actually tagging the user. In summmary, I am looking to be able to tag a user through a discord.js bot. Any help would be greatly appreciated, thanks! 回答1: You have two options. You can either use the toString method

Collection#find: pass a function instead

痴心易碎 提交于 2019-12-13 08:58:46
问题 I'm fairly new to node.js and I'm working on a discord bot with discord.js, I'm am trying to do assigned roles with commands. When I do the code and type in the command it works successfully but pops up with "DeprecationWarning: Collection#find: pass a function instead" in the console, how can I get rid of this? https://i.imgur.com/agKFNsF.png 回答1: This warning is caused by the following line: var role = message.guild.roles.find('name', 'Epic Gamer'); On an earlier version of Discord.js, this

How to fix “Cannot read property 'react' of undefined” in discord.js

[亡魂溺海] 提交于 2019-12-13 04:38:45
问题 I'm setting up a discord bot with reactions, but there is an error in the second reaction by number, but I can not find it. It's probably a loop error, but I've already tried to change the names of variables, nothing helps. I am also sorry for the length of the code, but I have tried to shorten it to the maximum. After hitting command !bot , the bot should reply with a message with 5 possible reactions. If I press reaction 1 , a second message appears with the description, the discord and the

Sqlite Discord.js: Cannot read property 'run' of null

谁说我不能喝 提交于 2019-12-13 04:12:37
问题 So I am trying to make a SQLite database for my Discord.js bot, but I keep getting this error (Cannot read property of 'run' of null) when I try to use SQLite. Non of my friends seem to have this problem, so I thought to come here. Sorry if this is like a noobish question.. I'm still a little new to this Here is my code: const Discord = require("discord.js"); const client = new Discord.Client(); const bot = new Discord.Client(); const sql = require("sqlite") const fs = require("fs"); const

How do I send number boxes emojis (1️⃣)?

瘦欲@ 提交于 2019-12-13 03:46:13
问题 How do I send them? If I try this: msg.react('1️⃣') it replies with an error telling me that this is an unknown emoji. What shall I do? client.on("message", async msg => { if (command === 'vote') { msg.channel.send('response') .then(m => m.react('1️⃣') } } 回答1: Taken from discordjs.guide ( the opensource guide maintained by the discord.js community). Do something like ( or just copy and paste the numbers ): // emojiCharacters.js module.exports = { a: '🇦', b: '🇧', c: '🇨', d: '🇩', e: '🇪', f: '🇫