Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
So basically when i run a command, the bot spams its response.
bot.on('message', message => {
let args = message.content.substring(PREFIX.length).split(" ");
switch (args[0]){
case 'embed':
const embed = new Discord.RichEmbed()
.setTitle('User Information')
.addField('Player Name', message.author.username)
.addField('Version', version)
.addField('Current Server', message.guild.name)
.setThumbnail(message.author.avatarURL)
.setFooter('Made By NotBanEvading')
message.channel.sendEmbed(embed);
break;
}
})
https://gyazo.com/a1c71fc097e1253bc036d1ef293f034e
bot.on('message', message =>.. means an event when the bot receives any messages.
Which means it will trigger when it recieves message from itself or other bots.
You can check if the message's author is a bot using message.author.bot, like so:
bot.on('message', message => {
// Do nothing if the message is from a bot.
if (message.author.bot) { return; }
let args = message.content.substring(PREFIX.length).split(" ");
// ... Rest of your codes
(P.S please make your title clearer on what you are actually asking. Rather than stating that you need help.)
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 months ago.
Improve this question
used by default Slashcommand
But I want to use more commands
like this '!'
How can do that??
I hope your response
Enable the MessageContent privileged intent in the Discord Developer Portal, then you can add an on message listener
client.on('messageCreate', (message) => {
if (message.author.bot) return; //return if the author is a bot
if (message.content === '!ping') {
console.log('Pong!') //execute command code here
}
});
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
How can i stop the spamming?
I want every member to get only one msg
client.guilds.cache.forEach(guild => {
message.channel.send (guild.name)
message.guild.members.cache.forEach(member => {
if (member.id != client.user.id && !member.user.bot) member.send(`testing`).catch(e => console.error(`Couldn't DM member ${member.user.tag}`));
});
});
Well according to what I think you were trying to do (send a message to all users), this is the code I came up with
await client.users.fetch();
let users = client.users.cache.filter(u => !u.bot);
for (const user of users) {
user.send('testing').catch(e => console.log('…'))
}
This code should work, and is easily readable, but please note that you may get ratelimited by trying to send messages to a lot of users in DM in a short time.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I made this command called p!poll [message] where I want my bot to send an embed with [message] for the description and react with the emojis 👍 and 👎. The command, however, isn't responding and I don't understand why.
#client.command
async def poll(ctx, *, message):
embedVar = discord.Embed(title='Poll', description=f'{message}')
msg = await ctx.channel.send(embed=embedVar)
await msg.add_reaction('👍')
await msg.add_reaction('👎')
Your command is forgetting to call the command, which is the double parenthesis, ()
Simply can be fixed by adding: client.command() to the top where it previously says without the parenthesis
It's better to include "None" in your message decorator, as it allows members to know they must pass a message through, otherwise it would not run the command.
I choose to optionally add some more functionality to your command, (only if you wish for use) and the option of sending it to a different channel, but I have tried this and should work. Hope this helps, change it to whatever you need.
#client.command()
async def poll(ctx, *, message=None):
if message == None:
await ctx.send(f'Cannot create a poll with no message!')
return
questions = [
f"Which channel should your poll be sent to?"
]
answers = []
def check(m):
return m.author == ctx.author and m.channel == ctx.channel
for i in questions:
await ctx.send(i)
try:
msg = await client.wait_for('message', timeout=30.0, check=check)
except asyncio.TimeoutError:
await ctx.send("Setup timed out, please be quicker next time!")
return
else:
answers.append(msg.content)
try:
c_id = int(answers[0][2:-1])
except:
await ctx.send(
f"You didn't mention a channel properly, please format like {ctx.channel.mention} next time."
)
return
channel = client.get_channel(c_id)
embed = discord.Embed(title="Poll", description='{message}', colour=discord.Color.black())
message = await channel.send(embed=embed )
await message.add_reaction('👍')
await message.add_reaction('👎')
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I want to make a system of when the user changes their nickname on the server and puts an emoticon that I set in the configuration she wins a position for example:
Your nickname on the server is User and you change it to User 🍬 then you get a role because you used the 🍬 that was defined in the settings of the bot.
can anyone help me with this?
I would use the npm package emoji-regex to match unicode emotes in the member's nickname, the GuildMember.nickname property to actually get the member's nickname, and the guildMemberUpdate event which will emit whenever someone's nickname is changed, among other things.
const emojiRegex = require('emoji-regex'); // require the package
client.on('guildMemberUpdate', (oldMember, newMember) => {
if (oldMember.nickname === newMember.nickname) return; // only execute code if the nick changed
if (emojiRegex().test(newMember.nickname)) { // if the member has a unicode emoji in their nick
// code...
}
});
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
Some users get an error saying Missing Permissions which means that the bot isn't able to locate the channel, there are three ways of being able to fix this error, two ways are below here, the first option isn't the best option. The 3rd option is the answer below.
if (!message.guild.me.hasPermission('VIEW_CHANNEL')) {
return message.channel.send('I can\'t find the voice channel, make sure I have the `View Channel` permission.')
}
// The member has to be in a voice channel
if (!message.member.voice.channel.permissionsFor(<Client>.user).has('VIEW_CHANNEL')) {
return message.channel.send('I can\'t find the voice channel, make sure I have the `View Channel` permission.')
}
Well it can be variable, some voice channels allowed some are not,
So you need to have an instance of a specific VoiceChannel and then you can use .joinable property
https://discord.js.org/#/docs/main/stable/class/VoiceChannel?scrollTo=joinable
const channel = <VoiceChannel>
if(!channel.joinable) {
return message.channel.send({
embed: {
color: colours.error,
description: 'I can\'t find the voice channel, make sure I have the `View Channel` permission.',
},
});
}