Discord.py bot speak message - discord

I have been looking for a way to make a bot speak out loud an edited message, using tts=True works fine when the message is first send. However, it doesn't work when it is edited. Here is the code I have tried.
msg = await ctx.send(content='Hello world', tts=True)
await msg.edit(content="I said hello", tts=True)
Couldn't find anything on google. Hopefully, somebody here knows how to do it.

Related

Discord Autocode reaction reply bot (not reaction role bot)

I have been using autocode.com to create some Discord bots. I have very little programming experience and found autocode to be quite easy. However, I've tried asking a question on autocode's discord that no one seems to understand or is asking.
I am trying to create a bot that replies to reactions--but does not assign roles, but instead, provides a reply--either in thread or a DM to that user who uses that specific emoji reaction.
For example, this is what I am looking to do: if there is a bot message in #channelx, userX will react to that message with a pepperoni emoji and then a pizza bot will reply back with a message either in thread or DM such as, "Hi #userx, your pizza topping has been recorded and will be ready for pickup in 15 minutes, please visit this link.com to track your order".
Autocode has a bot that can react to reactions and assign roles but I can't seem to reverse engineer it give a reply, rather than assign roles.
I appreciate any assistance. Thanks!
What does autocode use? Python or node.js? If python, you can do something like this:
#client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('message'):
await message.channel.send('hi')
If node.js, you can do something like this:
client.on('messageCreate', msg => {
if (msg.content === 'specific message') {
msg.reply(`response text`);
}
});
I was previously a Community Hero at the Autocode Discord server. Try finding another app through this, and if none are available, the thing to do would be looking through the API's. Here's one for messaging in general, here's one for responding, and here's one for dm-ing.
Let's say, for example, I'd be making it reply to a reaction through DM:
The first thing you do is make sure the event trigger is set to message.reaction.add. This is so that the code you will write is triggered whenever a reaction is added.
Make either a switch or if statement to change what happens depending on what reaction triggers the code. In this example, I'll just use an if statement for easy explanation.
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
if (context.params.event.emoji.id == '1234567890') {
await lib.discord.users['#0.2.1'].dms.create({
recipient_id: `${context.params.event.member.user.id}`,
content: `Hi <#${context.params.event.member.user.id}>, your pizza topping has been recorded and will be ready for pickup in 15 minutes, please visit this link.com to track your order`
});
}
What this does is check if the thing that triggered this event has the emoji id equaling '1234567890': If it does, then it follows into that if statement, and if it does not, it skips over it.
In the future, please stay patient in the Autocode Discord server; The ones who are helping are also community members, similar to here. You may always ask the same question every now and then.

How can I make a discord bot send a certain message in any channel

so I'm trying to make a discord bot (javascript) to ping my friend every time he talks. What I've tried so far are things like this from different websites:
client.on('message', msg => {
if (msg.author.id === '<#ID>') {
msg.channel.send('<#ID>')
}})
I've searched around and I can't find anything that works exept the msg.reply which I don't want to use because it pings the author. If anyone could help me that would be great, thanks

discord.js make a bot delete a given number of messages

I've started creating a discord bot and I've wanted it to start moderating my server. my first command to try was 'mass delete' or 'purge' which deletes the number of messages a user gives.
But I'm pretty new to java and discord.js so I have no idea how to start.
// code here to check if an mod or above
// code to delete a number of message a user gave
}```
For permissions checking, you could simply check for the message author's roles using:
if (!message.member.roles.cache.has(moderator role object)) return;
Overall, you should be looking at the bulkDelete() function that can be found here.
Although, since you don't really know how to really develop bots yet from what you're saying, I won't be telling you the answer to your problem straight ahead. I'd highly recommend learning some JavaScript basics (Also, keep in mind Java != JavaScript) as well as Discord.js basics before you jump head straight into what you want to create.
I'd highly recommend WornOffKeys on YouTube, they're fantastic.
Check user permission first using
if (!message.member.hasPermission("MANAGE_MESSAGES")) return message.channel.send("You have no permission to access this command")
check bot permission using
if (!message.guild.me.permissions.has("MANAGE_MESSAGES")) return message.channel.send("This bot have no permission to delete msg!")
return a message when user havnt mention a select message
if (!args[0]) return message.channel.send("no messages have been selected")
then as Bqre said using bulkdelete()
try {
await message.channel.bulkDelete(args[0])
} catch (e) {
console.log(e); //err
}
hope you find it useful!

How to let my discord bot respond to a message without a prefix

I'm pretty new to C# and am coding a discord bot for my own server. I'm trying to get my bot to respond to a message sent by someone (E.G someone says "dye" and my bot would respond with "no u" without prefix needed.
I've been searching all over the internet and know I need something along the lines of a "messagereceived event" but it keeps saying that it doesn't exist or I'm not using the directive or an assembly reference.
I'm not sure how to fix it or what I'm doing wrong since I'm quite new, and I can't find a solution. Hope someone can help
So I think what you are asking is having the bot detect when a certain phrase is said and then respond.
Assuming you are subscribed to the MessageReceived event (the event that runs everytime a new message is sent anywhere your bot is on) You get the given SocketMessage and get its content property. If that property matches "no u" then just have it reply in that channel. To do that get the context via something like this:
Subscribe to the MessageRecieved event:
_discord.messageRecieved += MessageReceivedEvent; //where _discord is your DiscordClient and MessageReceivedEvent is your task to run on that event
public async Task MessageReceivedAsync(SocketMessage message)
{
if(message.Content.equals("dye")
{
message.Channel.SendMessageAsync("no u");
}
//command implementation here
}

Reply to anyone who sent a DM

EDIT: Another question with better answers: How to reply to any DMs sent to the bot?
Is it possible to reply to someone who sent a message to my Discord.js bot?
For example, when someone sends hi to my bot's DMs, the bot should reply Please use !help for the commands' list.
I've tried a lot of attempts to use the MessageCollector but I failed doing it.
Any help would be appreciated.
Thanks!
You can just tell the bot to do that with client.on('message').
Try this:
client.on('msg', () => {
if (msg.channel.type == 'dm' && msg.content.toLowerCase() == 'hi')
msg.channel.send('Please use !help for the commands' list.')
})
This is just a quick example, but you can also add checking for commands and all the other stuff that you do on normal guild channels. To check if the message comes from a DMChannel is to check Channel.type

Resources