Reputation: 27
Ive never had this issue before. All of my other bots work perfectly, and im convinced its not my source code. When I start my bot, i get the following error message:
Traceback (most recent call last):
File "C:\Users\Overdrive\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\client.py", line 377, in _run_event
await coro(*args, **kwargs)
File "C:\Users\Overdrive\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\bot.py", line 1164, in on_connect
await self.sync_commands()
File "C:\Users\Overdrive\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\bot.py", line 719, in sync_commands
registered_commands = await self.register_commands(
File "C:\Users\Overdrive\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\bot.py", line 588, in register_commands
data = [cmd["command"].to_dict() for cmd in filtered_deleted]
File "C:\Users\Overdrive\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\bot.py", line 588, in <listcomp>
data = [cmd["command"].to_dict() for cmd in filtered_deleted]
File "C:\Users\Overdrive\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\commands\core.py", line 844, in to_dict
"options": [o.to_dict() for o in self.options],
File "C:\Users\Overdrive\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\commands\core.py", line 844, in <listcomp>
"options": [o.to_dict() for o in self.options],
File "C:\Users\Overdrive\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\commands\options.py", line 318, in to_dict
"type": self.input_type.value,
AttributeError: 'NoneType' object has no attribute 'value'
After the error, the bot starts but doesnt show any slash commands in the servers. I am using this invite link:
my code:
import discord
from discord.ext import commands
import os
intents=discord.Intents.all()
client=commands.Bot(intents=intents)
@client.event
async def on_ready():
print(f'\n\nSuccessfully logged into Discord as "{client.user}"\nAwaiting user input...')
await client.change_presence(status=discord.Status.online, activity=discord.Activity(type=discord.ActivityType.playing, name="all by myself..."))
@client.slash_command()
async def lol(interaction: discord.Interaction, ctx: discord.ApplicationContext):
await interaction.response.send_message("LOL")
client.run(os.environ.get("TOKEN"))
Any help is appreciated! For the life of me I cannot figure out whats happening.
Upvotes: 0
Views: 2907
Reputation: 1
You should try using the discord.app_commands library.
Here's your code updated:
import discord
from discord import app_commands
import os
class prepareclient(discord.Client):
def __init__(self): super().__init__(intents=discord.Intents.all())
async def on_ready():
print(f'\n\nSuccessfully logged into Discord as "{client.user}"\nAwaiting user input...')
await client.change_presence(status=discord.Status.online, activity=discord.Activity(type=discord.ActivityType.playing, name="all by myself..."))
await tree.sync()
client = prepareclient()
tree = app_commands.CommandTree(client)
@tree.command(name="lol", description=f"lol")
async def lol(inc: discord.Interaction):
await inc.response.send_message("LOL")
return
client.run(os.environ.get("TOKEN"))
I hope this helps.
Upvotes: 0
Reputation: 2102
Your interaction parameters are wrong. Should be:
import discord
from discord.ext import commands
import os
intents=discord.Intents.all()
client=commands.Bot(intents=intents)
@client.event
async def on_ready():
print(f'\n\nSuccessfully logged into Discord as "{client.user}"\nAwaiting user input...')
await client.change_presence(status=discord.Status.online, activity=discord.Activity(type=discord.ActivityType.playing, name="all by myself..."))
@client.slash_command()
async def lol(ctx: discord.ApplicationContext):
await ctx.response.send_message("LOL")
client.run(os.environ.get("TOKEN"))
Using your code with my changes allowed it to run without throwing an exception and I was able to invoke the lol
slash command.
Slash command docs. Slash commands have the ctx
(ApplicationContext) parameter and then other parameters are usually slash command options.
Upvotes: 2