I keep on getting the error “NameError: name ‘r’ is not defined”.Here is my code:
` import discord
from discord import app_commands
from discord.ext import commands
import nest_asyncio
nest_asyncio.apply()
intents = discord.Intents.all()
bot = commands.Bot(command_prefix="/", intents = discord.Intents.all())
@bot.tree.command(name="joinrole", description="Set the role ID when someone joins")
@app_commands.describe(join_role = "Enter Role ID")
async def join_role(interaction: discord.Interaction, join_role: str):
global r
await interaction.response.send_message(content="Set the join role ID to " + join_role + ". Note: If this doesn't work, your ID probably is invalid!", ephemeral=True)
r = join_role
@bot.tree.command(name="checkjoinrole", description="Shows the role ID when someone joins")
async def check_join_role(interaction: discord.Interaction):
await interaction.response.send_message(content="The join role ID is " + str(r), ephemeral=True)
@bot.event
async def on_member_join(member):
role = discord.utils.get(member.guild.roles, id=str(r))
await member.add_roles(role)`
I tried everything I swear to god. I just want to make a customizable role on join for my server. Every time I do it I get NameError: name 'r' is not defined
I tried a lot. So I want to make a customizable role on join, so I’m trying to add commands to set the role ID, rather than setting it in the file itself. Don’t worry about permissions I will add later.
Alcha is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.