DiscordJS MongoDB Ban System | DiscordJS v14 Tutorial

Durum
Üzgünüz bu konu cevaplar için kapatılmıştır...
Onaylı Üye
Katılım
16 Tem 2019
Mesajlar
50
Tepki puanı
0
Ödüller
4
Yaş
26
6 HİZMET YILI
peki bu kısmı nerden açıyoruz googleden mi
 
Üye
Katılım
27 May 2023
Mesajlar
8
Tepki puanı
0
Yaş
31
3 HİZMET YILI
any one dis cord user dm me i want togther play pubg
 
Onaylı Üye
Katılım
30 Eki 2021
Mesajlar
53
Çözümler
1
Tepki puanı
0
Ödüller
4
Yaş
31
4 HİZMET YILI
  1. Create a new Discord bot project.
  2. Install the following dependencies:
Code snippet
npm install discord.js @types/discord.js mongodb mongoose

Use code with caution.
Bağlantıları görmek için lütfen Giriş Yap

content_copy
  1. Create a new file called index.js and add the following code:
Code snippet
const Discord = require('discord.js');
const mongoose = require('mongoose');

// Create a new MongoDB connection
const uri = 'mongodb://localhost:27017/discord';
mongoose.connect(uri, { useNewUrlParser: true });

// Create a new Discord client
const client = new Discord.Client();

// Create a new Ban model
const Ban = mongoose.model('Ban', {
userID: {
type: String,
required: true,
},
reason: {
type: String,
required: true,
},
});

// Listen for the `message` event
client.on('message', async (message) => {
// Check if the message author is a moderator
if (!message.author.isModerator()) {
return;
}

// Check if the message contains the `/ban` command
if (message.content.startsWith('/ban')) {
// Get the user ID from the message
const userID = message.content.split(' ')[1];

// Create a new Ban object
const ban = new Ban({
userID,
reason: message.content.slice(message.content.indexOf(' ') + 1),
});

// Save the ban to the database
await ban.save();

// Send a message to the channel confirming the ban
message.channel.send(`User ${userID} has been banned. Reason: ${ban.reason}`);
}
});

// Start the Discord client
client.login('YOUR_BOT_TOKEN');

Use code with caution.
Bağlantıları görmek için lütfen Giriş Yap

content_copy
  1. Save the file and run the following command to start the bot:
Code snippet
node index.js

Use code with caution.
Bağlantıları görmek için lütfen Giriş Yap

content_copy
  1. Once the bot is started, you can ban users by sending the following message to a channel:
Code snippet
/ban <userID> <reason>

Use code with caution.
Bağlantıları görmek için lütfen Giriş Yap

content_copy
For example, to ban the user with the ID 1234567890, you would send the following message:

Code snippet
/ban 1234567890 This user is being banned for spamming.

Use code with caution.
Bağlantıları görmek için lütfen Giriş Yap

content_copy
The user will then be banned from the channel, and they will not be able to send messages.

You can also unban users by sending the following message to a channel:

Code snippet
/unban <userID>

Use code with caution.
Bağlantıları görmek için lütfen Giriş Yap

content_copy
For example, to unban the user with the ID 1234567890, you would send the following message:

Code snippet
/unban 1234567890

Use code with caution.
Bağlantıları görmek için lütfen Giriş Yap

content_copy
The user will then be unbanned from the channel, and they will be able to send messages again.

This is just a basic example of how to create a DiscordJS MongoDB Ban System. You can customize it to fit your needs by adding additional features, such as a list of banned users, a way to appeal bans, and so on.
Videolu anlatım olsa daha iyidi yinede eline sağlık
 
Durum
Üzgünüz bu konu cevaplar için kapatılmıştır...
Üst