Y
Y
Yaroslav Kuznetsov2020-06-10 10:39:07
Node.js
Yaroslav Kuznetsov, 2020-06-10 10:39:07

How to make a bot that will send a certain text to all participants?

I write in Visual Studio Code, in node.js. I know a little about programming. Thanks in advance.
I will also be grateful if you write how, by writing, for example, the% help command, the bot would write the text in several paragraphs in one sentence

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
VELAND, 2020-06-12
@VELAND

You can do something like this, I think the basic principles of work should be clear, despite my crooked code, tabs and errors) PS The code is written on the [email protected] version

const Discord = require('discord.js');
const client = new Discord.Client();
const prefix = "/" // Префикс команды, на которую будет регировать бот

try{

client.on("message", (message) => {
  if (!message.content.startsWith(prefix) || message.author.bot) return;
  const args = message.content.slice(prefix.length).split(/ +/);
  const command = args.shift().toLowerCase();
  
  if (command === 'sendall') {
    message.delete();
    if(!message.member.hasPermission('ADMINISTRATOR')){ // Необходимые права для доступа к команде. Все права можно посмотреть по ссылке https://discord.com/developers/docs/topics/permissions
      message.delete();
      return message.reply("Данная команда доступна только администраторам").then(msg => {
        msg.delete(5500)
        });
    }
    const msgc = args.slice(0).join(' ')
    message.guild.members.forEach(m => {
    m.sendMessage(msgc)
    .catch(`Невозможно отправить сообщение пользователю ${m.nickname}`);
    });
    message.reply(`Вы великолепны! Команда успешно выполнена!`).then(msg => {
      msg.delete(5500)
      });
}
});

} catch(err){
  console.log("Ошибка")
}

client.login("Ваш Токен");

A
Averyanalex, 2020-06-10
@Averyanalex

Oh, this is a very long topic to be honest. So just don't answer. Google discord.py, then there's this thing like:
import discord
from discord.ext import commands
bot = commands.bot("bot prefix")
bot.command()
async def sender(ctx, memb: discord.Member):
memb .send("I WRITE TO YOU!!!")
bot.run("your token is here")
PS This is a complete working code, add the bot to the server, run it in python 3, also pip3 install discord, write on the server !sender @mention instead of ! Prefix

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question