#slash.slash(name='spam', description='I will spam your content for times!', options=optionsspam, guild_ids=[847769978308526090])
async def spam(ctx, text: str, times: int="15"):
if bool(times):
Times = 15
else:
Times = times
for i in range(int(Times)):
await ctx.send(text)
await asyncio.sleep(.7)
And the result is:
It keeps replying to the first message that the bot sent. I don’t want the bot to reply. I want it to just send a normal message. How?
An interaction (slash-command) will always require a direct response towards the user. If you do not use ctx.send(str), the interaction will fail.
You've got 2 options to make it seem, like you are not responding to the slash command
Hide the response
You can post a hidden answer ctx.send('ok', hidden=True) and then send the intented message into the channel ctx.channel.send(str).
This will make the initial 'ok' only visible for the invoking users and all other members of the server will neither see the request, nor the first response.
Delete the response
Your second option is to automatically delete the answer after a very short period (ctx.send('ok', delete_after=1)), followed by a normal message into the channel ctx.channel.send(str).
Defering the response
You might need to defer your response if you can't respond within 3 seconds of the invocation. Defering an interaction (ctx.defer(hidden=True) or ctx.defer()) must be called with the same hidden attribute as your future ctx.send().
If you want to hide your respons ctx.send('ok', hidden=True), you need to defer in the same state ctx.defer(hidden=True).
You could get the channel and send message to the channel directly. However, you then must use something like ctx.defer() so that the interaction doesn't get displayed as failed.
#slash.slash(name='spam', description='I will spam your content for times!', options=optionsspam, guild_ids=[847769978308526090])
async def spam(ctx, text: str, times: int="15"):
channel = ctx.channel
if bool(times):
Times = 15
else:
Times = times
for i in range(int(Times)):
if channel != None:
await channel.send(text)
await asyncio.sleep(.7)
await ctx.send("Done")
Related
I am using Discordjs v13. I have created a slash command and I am able to "print" a message using
await interaction.reply(messageObj);
I need to send the reply to a different channel where the command was triggered, is this possible?
Something like:
interaction.setChannel(channelId).reply(...)
OR
interaction.reply({
channel: ....
....
})
What you want is not possible. The Discord API does not allow to specify the channel where the app interaction should be replied in: https://discord.com/developers/docs/interactions/receiving-and-responding#responding-to-an-interaction
However if you are concerned with the reply being shown to everyone, you can make the reply ephemeral. If you want to log interactions, you can reply to the interaction then send another message using the solution provided in the comments of your question.
this is actually possible in discordjs v14 and may be in v13 as well. Carl-bot does it with suggestions.but its not an actual reply
use
interaction.guild.channels.cache.get('channel-id').send('message')
this will send a message in a the select channel you may still want to
interaction.reply({Content:'replied in #channel' [embed], ephemeral: true })
so the user knows the reply was redirected . ephemeral: true makes the replay only visible to the user that evoked the interaction.
and if you need the message id for the new message use
const msg = await interaction.guild.channels.cache.get('channel-id').send('message');
to send the message and you can do something like const messageid = msg.id
I'm trying to create a slash command using discord.js v13 to change the names of voice channels. I am using this code to do this :
module.exports = {
data: new SlashCommandBuilder()
.setName('name')
.setDescription('Set name for your voice channel')
.addStringOption(option => option.setName('name').setDescription('Enter your name').setRequired(true)),
async execute(interaction) {
const name = interaction.options.getString('name');
if (!interaction.member.voice.channel) await interaction.reply('Error not in a voice channel!');
else {
await interaction.member.voice.channel.setName(name);
await interaction.reply('Done!');
}
},
};
This code is fine and makes the job done. But as you know I can change the voice channel's name only 2 times per 10 minutes because of the limit rate. So if a user tries to change the voice channel's name for the third time, I won't get any error on the console, and discord js will queue this request for later and will do it after 10 minutes. But the user gets this error on discord: This interaction failed.
I want to check if there was a rate limit for my request, and if is, don't send the request and just reply to the user. Is this possible?
There is no inherent functionality that is able to handle the situation in the way you want it to, but the problem is soluble using regular old JavaScript. For example, you could use an integer to indicate how many times the command has been used and use setTimeout() to decrement it 10 minutes after the command was called. That way you can check if the int is equal to 2 in which case you skip the .setName().
There are undoubtedly other ways to implement the same or similar behavior, but, to answer your question, unfortunately the discordjs/voice library does not provide any simple way to do it.
I'm making a bot command that...
Locks the channel; making no one able to send messages.
Sends an image and a message.
Waits 10 seconds before unlocking the channel, allowing others to send images.
However, I have tried different messages such as changing the role name and different sleep times, and the bot does not send a message, modify commands, or what it was intended to do. It is only this command that doesn't function, and no errors pop up in the console.
Could someone help me, please?
#commands.has_permissions(manage_messages=True)
async def warudo(ctx):
await ctx.channel.set_permissions(ctx.verified, send_messages=False)
await ctx.send('***Za Warudo!***')
await ctx.send(file=discord.File('https://pics.me.me/thumb_you-thought-it-was-an-emoji-but-it-was-me-71487398.png'))
await ctx.send( ctx.channel.mention + "has paused.")
await asyncio.sleep(10)
await ctx.channel.set_permissions(ctx.verified, send_messages=True)```
I would like to ping a user in a channel (to alert them to it) then delete the message.
I have seen this on many large discord servers, they use custom bots for it so I think it wouldn't be too hard!
Inside your guildMemberAdd event get, the channel you want to send the ping in, then do channel.send(`${member.user}`).
Here, member is the argument you gave to the callback function in the event. member.user will ping them in that channel.
send() method returns the message you sent as a promise, which means you can just catch that message and delete it like this: send().then(message => message.delete()).
You can provide timeout as an optional parameter to the delete() method if you want to delete the message after a specific period of time and not instantly. This is what the whole code will look like:
bot.on('guildMemberAdd', (member) => {
const channel = member.guild.channels.cache.get('id'); // get the channel using the id
channel.send(`${member.user}`)
.then(message => message.delete());
}
I'm trying to add certain files from being posted to the general channel as we have designated channels for certain attachments, clips, videos, music, etc. I'm fine on getting the bot to recognize links, however, having a hard time getting it to recognize attachments, more specifically, .mp4 attachments.
I added a whitelist of acceptable attachments in an array, then try and check the message author attachment to see if it's okay to post, if its an .mp4 it should be deleted.
The try function is within the on_message event decorator.
whiteList = ['bmp','jpeg','jpg','png']
try:
for attachment in message.attachments:
#Get general channel ID
channel = client.get_channel(521376573245358081)
if message.channel is channel and attachment['filename'].split('.')[-1] not in whiteList:
await message.delete()
botsMessage = await channel.send("{0.mention} Please refrain from posting videos in General. You may post them in #videos".format(message.author))
await asyncio.sleep(5)
await botsMessage.delete()
except:
print('Unknown error')
No error comes of this as when I test this the attachment remains, the bot passes over the function and prints the console message (used for debugging to make sure the code reaches that far). Any suggestions?
attachment['filename'].split('.')[-1]
You treated attachment as an dictionary that has a key called filename.
You should have treated attachment as an object that has a property called filename as follows:
attachment.filename.split('.')[-1]
Also, you should break the loop whenever the message is deleted,
# ...
botsMessage = await channel.send("{0.mention} Please refrain from posting videos in General. You may post them in #videos".format(message.author))
await asyncio.sleep(5)
await botsMessage.delete()
break
# ...
in the event that the user have sent mutiple video files, the loop will still continue even after you delete the message. Which may cause it to try to delete a deleted message
The break statement prevents the above from happening.