'NameError: name 'guildticket' is not defined
When I try to react with this reaction emoji on discord "🎮", i dont get the discord role i should get (Mitglied). Only "NameError: name 'guildticket' is not defined" comes out at the console. I don't know what I should do, maybe you can help me :)
import discord
from discord import Color, channel, client
from discord.ext import commands
bot = commands.Bot(command_prefix=".")
@bot.command()
async def open(ctx):
global guildticket
guildticket = ctx.guild
embed = discord.Embed(
colour=Color.red()
)
embed.add_field(name="j4nluca's Ticket Bot", value="Reagiere mit \":envelope_with_arrow:\", um ein Ticket zu erstellen")
embed.set_footer(text="Das Ticket funktioniert nicht? Schreibe: !open")
await ctx.channel.purge(limit=1)
emoji = "📩"
message = await ctx.send(embed=embed)
await message.add_reaction(emoji=emoji)
@bot.event
async def on_ready():
print("\"Blokki\'s Bot\" erfolgreich geladen")
activity = discord.Activity(type=discord.ActivityType.watching, name="Blokkmonsta zu")
await bot.change_presence(activity=activity, status=discord.Status.online)
@bot.event
async def on_reaction_add(reaction, user):
if user.id != 901815052091416616:
guild = guildticket
channelexists = discord.utils.get(guild.text_channels,name=user.name.lower().replace("#",""))
if channelexists:
None
else:
botrole = discord.utils.get(guild.roles, id=901816835123576874)
if reaction.emoji == '📩' :
category = discord.utils.get(guild.categories, id=969921517985099790)
channel = await guild.create_text_channel(name=f"{user.name}", category=category)
await channel.set_permissions(user, view_channel=True)
await channel.send(f"{botrole.mention}")
await channel.send(f"**`Ticket von {user.name}`**")
await channel.send("Bitte schildere uns der Einfachkeit halber dein Problem möglichst ausführlich.")
await channel.send("Sollte sich dein Problem geklärt haben, nutze .close")
if reaction.emoji == '🎮':
roles = discord.utils.get(user.guild.roles, name='Mitglied')
await user.add_roles(roles)
```
...
Solution 1:[1]
You need to define and initiate guildticket as an empty variable in the global scope.
import discord
from discord import Color, channel, client
from discord.ext import commands
bot = commands.Bot(command_prefix=".")
guildticket = '' # Uses empty string as example (assuming ctx.guild is a string)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ben |
