I get an error when I run a command, this is my code:
let id = message.author.id.toString().substr(0, 4) + message.author.discriminator;
var name = `order-${message.author}-${id}`
guild.channels.create(name)
}
Error:
ReferenceError: guild is not defined
I hope someone can help me! :-)
You need to add message. before guild
message.guild.channels.create(name)
You can do as Syntle said
message.guild.channels.create(name)
or you can define a guild
let guild = message.guild
guild.channels.create(name)
Related
I'm a complete beginner so can someone please explain me what is wrong here and how to fix it? Thank you
from discord.ext import commands
from discord.utils import get
#client.command()
async def reserve(message, *, stand):
channel = message.channel,
author = message.author,
guild = message.guild,
the_world = get(message.guild.roles,name="The World"),
if stand == 'The World':
await message.author.add_roles(the_world)
The error:
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'tuple' object has no attribute 'id'
Assuming as the rest of your bot runs, your provided code causes this error as you are using get(ctx.guild.roles,name="The World") instead, make sure to use discord.utils in your argument:
discord.utils.get(ctx.guild.roles,name="The World")
Additionally I've modified some more of your code, as a command, you don't need to pass message as your parameters, use ctx and it's attributes.
#client.command()
async def reserve(ctx, *, stand):
if stand == 'The World':
the_world = discord.utils.get(ctx.guild.roles,name = "The World"),
await ctx.author.add_roles(the_world)
I am trying to make my bot's role a pink color for the current server using the Client.on("ready") However whenever I run the bot with what I currently have the console returns:
(node:6504) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'cache' of undefined
Here is my code I am currently using. I know I need to for loop on every guild but I'm not sure how I would do that, I could use a for or just a .forEach however I can't find the correct way to do such.
const role = client.guild.roles.cache.get('Aiz Basic+');
role.edit({ name: 'Aiz Basic+', color: '#FFC0CB' });
In advance thank you to anybody who replies and helps with my message.
Client#Guild Isn‘t existing. Only Client#Guilds. You can fix this problem by looping through the cache of all your guilds with:
client.guilds.cache.forEach((g) => { })
And inside the loop you can use your code after fixing the .get function, because the get function needs a role id not a role name. You could find the role via the name by writing:
const role = <Guild>.roles.cache.find((r) => r.name === /* The role name */);
Make sure you replaced <Guild> with your guild variable.
Try this code if client.guild is not defined, it could also be because you are using bot instead of client
let role = message.guild.roles.cache.find(role => role.name === "Aiz Basic+");
I want to do a mute command, but when I do the command, the console output is (node:67916) UnhandledPromiseRejectionWarning: TypeError: msg.guild.roles.get is not a function
Any ideas how i can fix that?
As the error message says, msg.guild.roles.get is not a function. Its quite hard to answer a question without seeing the code, you should always share your code, but the correct way to find and add a role is the following:
const role = message.guild.roles.cache.find(role => role.name === 'Muted');
const member = message.mentions.members.first();
if(!member) member = message.author;
member.roles.add(role);
Since the update to V12, it is important that when trying to get roles, members or guilds you must include the .cache bit.
I've got an issue when trying to add a role to a member programmatically. member.roles.add is throwing the following error:
(node:9420) UnhandledPromiseRejectionWarning: TypeError [INVALID_TYPE]: Supplied roles is not a Role, Snowflake or Array or Collection of Roles or Snowflakes.
I'd tried to pass in the id and name of the role to the add method but this did not work either. What am I doing wrong here? Any pointers in the right direction would be much appreciated.
Below is the functionality to apply the role itself (within its context) for better understanding of my issue:
bot.on('message', msg=>{
if(msg.content.match(/[`!##$%^&*()_+\-=\[\]{};':"\\|,.<>\/?~]/)) {
if((msg.content.match((new RegExp(/[`!##$%^&*()_+\-=\[\]{};':"\\|,.<>\/?~]/, "g")) || []).length) >= 30) {
msg.channel.send(`${"<#" + msg.author.id + ">"}. Your message has been deleted for containing too many special characters.`);
const guild = bot.guilds.cache.get(GUILD_ID_HERE);
let mute_role = msg.guild.roles.cache.find(role => role.name === 'spammer');
var member = guild.members.cache.get(msg.author.id);
member.roles.add(mute_role);
msg.delete();
}
}
...
im trying to make a change nickname command
if(isValidCommand(message, "changenick")){
try {
if (mention == null){return message.reply("changenick who? dumb dumb")}
nickname = message.content.slice(8 + mention);
let member = message.mentions.members.first();
member = await member.setNickname(nickname);
}
catch (e) {console.error(e);
return message.channel.send("something went wrong!");}
}
but i get the error DiscordAPIerror: missing permissions even when trying it in my own server
I would suggest the following:
Make sure the bot itself has the MANAGE_NICKNAMES permission.
A user can only change the nickname of a person below them in the role hierarchy, this applies to bots as well.