How do I make my bot repeat a message without the command? - discord.js

I would like to know if there's a way that I could make a say command but without the prefix + say.
if(msg.content.startsWith("!say")){
const say = new Discord.MessageEmbed()
.setDescription(`${msg.content`})
msg.channel.send(say)
This is my code, where it appears the "!say"
Can you help me? Thank you!

You can split message.content by spaces and remove the first value (which would be "!say") then join the rest.
if(msg.content.startsWith("!say")){
const filteredMessage = msg.content.split(' ').slice(1).join(' ');
const say = new Discord.MessageEmbed()
.setDescription(filteredMessage);
msg.channel.send(say);
}

Also you can try using this code which is more simple than Elitezen's code
if(msg.content.startsWith("!say")){
let text = args.join(" ");
const say = new Discord.MessageEmbed()
.setDescription(`${text}`);
msg.channel.send(say)}

Related

How to check if a specific thing exists in quick.db?

So i was making a discord game bot where you collect chracters by opening chests, but the problem is that the characters appear again when you already have them.
I used the method db.push
the code:
if(has === true){
console.log(has)
let embed = new discord.MessageEmbed()
.setTitle('Chest Opening | Clash Chest')
.setDescription("<#"+message.author+"> got:\n"+amount+" :coin:")
.setColor('RANDOM')
.setFooter('Created by Tahmid GS#1867')
message.channel.send(embed)
await db.fetch(`coin_${message.author.id}`)
db.add(`coin_${message.author.id}`, amount)
}
else if(has === false){
console.log(has)
await db.fetch(`troop_${message.author.id}`)
db.push(`troop_${message.author.id}`, nada)
let embed = new discord.MessageEmbed()
.setTitle('Chest Opening | Clash Chest')
.setDescription("<#"+message.author+"> got:\n"+amount+" :coin:\n||Common: "+nada+"||")
.setColor('RANDOM')
.setFooter('Created by Tahmid GS#1867')
message.channel.send(embed)
await db.fetch(`coin_${message.author.id}`)
db.add(`coin_${message.author.id}`, amount)
await db.fetch(`card_${message.author.id}`)
db.add(`card_${message.author.id}`, 1)
}
has is let has = db.has(troop_${message.author.id}, nada)
I used let has = db.has(troop_${message.author.id}.nada)
and let has = db.has(nada,troop_${message.author.id})
But it doesn't seem to work, in the console is "false"
nada is the random chracter
You are checking if the database has a specific key. In the database under the key troop_${message.author.id} there is an array. You want to check if that array includes the character or not.
let has = (db.get(`troop_${message.author.id}`) || []).includes(nada);
Also you might want to check for the possibility that db.get() returns undefined or something like that. In that case we call .includes() on an empty array. Instead of getting an error TypeError: Cannot read property 'includes' of undefined.

How to index into the channel.members list and take out the name? Closed

So I'm trying to get the names of all the people in a voice channel, but the bot returns a list like so:
[<Member id=704069756717629472 name='Eedward' discriminator='8402' bot=False nick=None guild=<Guild id=807690875802878003 name='lfg testing' shard_id=None chunked=True member_count=3>>]
Is there any way I can take that "name" part out of the list? Or is there a better way to do something like this? This is my code:
#client.command()
async def lfg(ctx, game, *,extra=None):
if not ctx.message.author.voice:
await ctx.send(f"{ctx.author.name}, you need to connect to a voice channel first to use this command.")
return
else:
channel = ctx.message.author.voice.channel
link = await channel.create_invite(max_age = 300)
members = len(ctx.message.author.voice.channel.members)
members1 = ctx.message.author.voice.channel.members
max_ = channel.user_limit
if max_ == 0:
max_ = 'None'
if max_ == 'None':
p = f'{members}, No Limit'
else:
p = f"{members} out of {max_}"
em = Embed(color=discord.Color.gold())
em.add_field(name='LFG Request', value=f"**{ctx.author.mention} is looking for a group in voice channel `#{channel}`**:\n\n**Game: {game}**\n\n**Extra Info:** {extra}\n\n**Connected Users:**{(members1)} ({p})\n\n**VC Invite: [Click here to join]({link})**")
em.set_footer(text=f'Type !lfg (message) to create this embed | This LFG request was made by {ctx.author.name}')
await ctx.send(embed=em)
Sorry if it's a bit hard to read, thanks in advance! :D (Btw I'm trying to display the names of the users in the vc in the "Connected Users" section of the embed)
Edit: I figured it out, for those who want the code, here it is:
members = len(ctx.message.author.voice.channel.members)
count = 0
members1 = ""
for _ in range(int(members)):
members1 += f"{ctx.message.author.voice.channel.members[count].mention}"
count += 1
try adding .name to the member. This should get the name from the member.

Why does my discord bot not send a variable?

I have a bot that needs to send a message with a set message, followed by an integer defined by a variable. When I run this, the bot reacts to the message correctly but then doesn't send any response whatsoever. Why? XD (and yes I'm kinda bad and new at coding but idc I am determined to get this to work!)
EDIT: Ok it's sending the text and variable now, but it always prints as 0. Anyone know why it's always zero?
else:
emoji = '\N{Cross Mark}'
await message.add_reaction(emoji)
await message.channel.send("You messed it up at:")
await message.channel.send(f'{bowl_count}')
bowl_count == int(0)
Are you using on_message?
Also are you checking if bowl_count is equal to 0?
You don't need to provide int() unless you have a variable called 0 that's value is a string (text in quote marks)
else:
emoji = '\N{Cross Mark}'
await message.add_reaction(emoji)
await message.channel.send("YOU MESSED IT UP AT: ", bowl_count)
bowl_count = 0
Other than that it looks fine.
If you are using commands, then do define an await ctx.send("TEXT") as a variable called message
else:
emoji = '\n{Cross Mark}'
await message.add_reaction(emoji)
await message.channel.send("YOU MESSED IT UP AT: " + bowl_count)
bowl_count == int(0)
first, the escaped \N doesn't work, try \n
second, just use + to concatenate the strings
As a starter, you can not add a reaction that way, I would recommend doing this;
await message.add_reaction('👍')
As for using a valuable, you can do it using a f string:
text = "Hello!"
await ctx.send(f'{text}')

Please help me with the code to send a message to the channel

I want the code to work what I wrote-test2 #chat and the bot sent a message there, but my code doesn't work. Please help me with the code and tell me where I made the mistake. I will be grateful!
My code:
#client.command()
async def test2(ctx, name):
chans = get(ctx.guild.channels, name = name)
e = discord.Embed(title = f'hello')
await chans.send(embed = e)
If you print the name argument, you'll get something like this <#771335478372204575>, it's not a channel name, neither an ID
Top fix it you can use converters
#client.command()
async def test2(ctx, channel: discord.TextChannel):
e = discord.Embed(title='hello')
await channel.send(embed=e)

Discord embed list

I want to print an embed item list but the empty spaces(blank field titles) between each item are bothering me and making it unnecessarily long.
So is there a way to print all the items from an array without having to keep adding new fields?
const list = new Discord.MessageEmbed()
.setTitle('Items')
.setColor('#0099ff')
for (var xc = 0; xc < (items.length-1); xc++)
{
var item = items[xc];
list.addField('\u200B',item);
}
msg.channel.send(list);
This is what I have at the moment.
Maybe set it as the description
list.setDescription(items.join("\n"));

Resources