So my discord bot smartwiki was recently verified and I have this event where it just sends undefined idk why.. advaith told it comes cause one of the bot server is on an outage but I tried removing bot from some guilds and those guilds weren't on an outage but I get undefined (I have presence intent btw) also thsi isn't cause of intents cuz my guild create works fine this did too but it got undefined after my bot went verified
Code:
client.on('guildDelete', guild =>{
client.user.setActivity(`Serving ${client.guilds.cache.size} Servers with a total of ${client.users.cache.size} users and ${client.channels.cache.size} Channels!`);
const Logs = '809839910675546122'
client.channels.cache.get(Logs).send(
new Discord.MessageEmbed()
.setTitle("I Was Removed From a Guild :c")
.addField("Guild Name" , `${guild.name}`)
.addField("Guild Members" , `${guild.members.cache.size}`)
.addField("Guild Id" , `${guild.id}`)
.addField("Guild Owner" , `<#${guild.ownerID}> | Id: ${guild.ownerID}`)
.setFooter(`SmartWiki is Currently in ${client.guilds.cache.size}guilds!`)
.setTimestamp()
.setThumbnail("https://cdn.discordapp.com/attachments/776925179947384884/808370331856535582/standard_1.gif")
.setColor('RED')
)
})
Image: https://imgur.com/a/IjdioBC
Getting the same thing recently with my bot. Don't know why. Seems to appear before the bot logs in and also after, has been for a few days now. Only on bootup though. Odd...
Related
I’m creating a discord bot using discord py and would like to have a kick command that dms the user a reason upon being kicked.
-kick #user reason
When I kick the user with a reason attached it doesn’t kick the user and I get an error in console saying can not find the user
Here is the code
#client.command(aliases=['Kick'])
#commands.has_permissions(administrator=True)
async def kick(ctx,member : discord.Member,*,reason= 'no reason'):
await ctx.send(f'{member.name} was kicked from the Server!\nand a Dm was sendet by me as a Information for him')
await asyncio.sleep(5)
await ctx.channel.purge(limit=2)
await member.send(f'**You was kicked from {ctx.guild.name}\nthe Stuff Team dont tell me the reason?**')
await member.kick(reason=reason)
print(f"{ctx.author} ----> just used {prefix}kick")
And yes I have tried Google, the discord py API guide with no luck
Can anyone help? Thanks
You can give a nice error message. It raises MemberNotFound.
Then you can make a local error handler.
#kick.error
async def kick_command_error(ctx, err):
if isinstance(err, commands.MemberNotFound):
await ctx.send('Hey! The member you gave is invalid or was not found. Please try again by `#`mentioning them or using the ID.')
when I ping my discord bot it shows what I made it say, but when someone replies to the bot it still sends the message, I want it to reply only when pinged.
You could add this into your messageCreateevent:
if (message.mentions.has(client.user.id)) return message.channel.send({ content: `My Prefix is ${prefix}` });
You should define your prefix first so it wont get called as undefined and for the bot to show your prefix.
For more information about Discord.js mention: discord.js documentation
client.on('messageReactionAdd', async (reaction, user) => {
if(reaction.message.id === "731619243249893417"){
const guildMember = reaction.message.guild.members.cache.get(user.id)
if(!guildMember.roles.cache.get("692177977705889845")){
guildMember.roles.add("692177977705889845");
Im using this code, but when i react to the message it
don't give me the role, im a starter needing help, thanks u all, and sorry for my english
Bots only listen for new messages. You have to tell them to listen for an old message explicitly to get a reaction from them. Try using this code. It fetches the message when a reaction is added to that message.
I'm coding a server-info command for my discord bot, and I want to get the owner username or tag from the actual guild. I found a way to do it in discord js 11, but it's not working anymore under 12th version :
const guild = client.guilds.get(message.guild.id);
message.channel.send(message.guild.member(guild.owner) ? guild.owner.toString() : guild.owner.user.tag);
// if the user is in that guild it will mention him, otherwise it will use .tag
So in discord js 12, client.guilds.get isn't a function, and guild.owner returns null.
message.guild.owner.user.usernameis also returning Cannot read property 'user' of null.
I took a look at the documentation, and message.guild.owner seems to be a real property (https://discord.js.org/#/docs/main/stable/class/Guild?scrollTo=owner). So I don't know why it's returning null.
I'd recommend that you first get the guild and make sure that it's available before trying to modify or access it. Therefore, your bot won't hit any errors. Additionally, as far as I know, guild.owner returns null but there is a way around this. You can get the guild owner ID through guild.ownerID and fetch the member as a guildMember. Here is the code:
const guild = message.guild; // Gets guild from the Message object
if(!guild.available) return; // Stops if unavailable
await message.guild.members.fetch(message.guild.ownerID) // Fetches owner
.then(guildMember => sOwner = guildMember) // sOwner is the owner
message.channel.send(guild.member(sOwner) ? sOwner.toString() : guild.owner.user.tag);
This is how you would get the owner's tag when you have the guild. This also does not rely on the cache, so if your bot restarts or the cache is cleared, it will work regardless.
let ownerTag = undefined;
<client>.users.fetch(<guild>.ownerID).then(user => ownerTag = user.tag);
.fetch() returns a promise, which is why I declared a variable and then assigned the value to it.
Make sure you enable these intents in your discord developer portal so your bot could access your server
After that, you could access your user owner tag.
So I'm making a kick command for my discord bot and I want the bot to DM the user telling them they have been kicked. So far I have got:
case 'kick':
const Embed = new
Discord.MessageEmbed()
.setTitle('Success!')
.setColor(0x00FF00)
.setDescription(`Successfully kicked **${args[2]}** \n \n**Message:** \n"${args.join(' ')}"`)
if(!message.member.hasPermission(['KICK_MEMBERS'])) return message.channel.send('*Error: You do not have permission to use* **kick**.');
if(!args[1]) return message.channel.send('*Error: Please specify a user to kick!*');
let member = message.mentions.members.first();
member.kick().then((member) => {
message.channel.send(Embed);
})
break;
So far, the user is successfully kicked so all this works.
All I need to know is how to make the bot DM the mentioned user to tell them they have been kicked. Any help is appreciated!
You are probably looking for this method: GuildMember#send()
member.send("Your DM Here");
Note that if the only reason your bot could send a member DMs was because of a mutual server in which the user had DMs from server members enabled (user disabled other types of stranger DMs), then your bot would not be able to send the DM. It would probably be a good idea to send them the DM and wait for the method's returned promise to resolve before kicking them, for a higher chance that the DM actually reaches them.