I'm using random library to choose the link randomly in my command. It worked perfectly, but then I wasn't able to use it anymore. Here is my code:
import nextcord
import random
from nextcord.ext import commands
from nextcord import Interaction, SlashOption, ChannelType
from nextcord.abc import GuildChannel
from nextcord.ext import commands
intents = nextcord.Intents.default()
intents.message_content = True
client=commands.Bot(command_prefix='!')
serverID= 1115682153087385691
rep=['Meow!', ':3', 'Nyaa~', 'UwU', 'OwO', 'ヾ(•ω•`)o', ':cat2:', 'ヾ(≧▽≦*)o', '(p≧w≦q)']
image=['link 1', 'link2', 'link3', 'link4']
@client.slash_command(name = 'ping', description="Replies with pong!", guild_ids=[serverID])
async def ping(interaction: nextcord.Interaction):
await interaction.response.send_message("Pong!")
@client.slash_command(name = 'meow', description="Meow!", guild_ids=[serverID])
async def ping(interaction: nextcord.Interaction):
await interaction.response.send_message('{}'.format(random.choice(rep)))
@client.slash_command(name = 'image', description="Random image.", guild_ids=[serverID])
async def image(interaction: nextcord.Interaction):
image_embed=nextcord.Embed(title="Meow!", description="ヾ(≧▽≦*)o", color=0xff9eb1)
image_embed.set_image('{}'.format(random.choice(image)))
await interaction.response.send_message(embed=image_embed)
@client.slash_command(name = 'about', description="About this bot", guild_ids=[serverID])
async def about(interaction: nextcord.Interaction):
about_embed=nextcord.Embed(title="Meow!", description="ヾ(≧▽≦*)o", color=0xff9eb1)
about_embed.set_author(name="Owner: Minh#6284")
about_embed.set_thumbnail(url="https://cdn.discordapp.com/attachments/1116376164433395742/1116376184368930948/48dbf3be4ac93bcf67243f3fcbfc50a4.png")
about_embed.add_field(name="About this bot:", value="A fun bot for everyone, with some mini games and cute cats images (catgirls too)!", inline=False)
about_embed.add_field(name="Support server:", value="https://discord.gg/cAS6E4NhZD", inline=False)
about_embed.set_footer(text="UwU")
await interaction.response.send_message(embed=about_embed)
@client.slash_command(name = 'suggest', description="Suggest us!", guild_ids=[serverID])
async def suggest(interaction: nextcord.Interaction, your_idea:str):
await interaction.response.send_message('Thanks for your ideas!', ephemeral=True)
print(your_idea)
And this is the Error message:
Ignoring exception in command <nextcord.application_command.SlashApplicationCommand object at 0x000001E4CD1CC910>:
Traceback (most recent call last):
File "C:\Users\Minh\AppData\Local\Programs\Python\Python311\Lib\site-packages\nextcord\application_command.py", line 890, in invoke_callback_with_hooks
await self(interaction, *args, **kwargs)
File "c:\Users\Minh\Desktop\Miko\main.py", line 28, in image
image_embed.set_image('{}'.format(random.choice(image)))
^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Minh\AppData\Local\Programs\Python\Python311\Lib\random.py", line 372, in choice
if not len(seq):
^^^^^^^^
TypeError: object of type 'SlashApplicationCommand' has no len()
The above exception was the direct cause of the following exception:
nextcord.errors.ApplicationInvokeError: Command raised an exception: TypeError: object of type 'SlashApplicationCommand' has no len()
How can I fix it? Is it a problem from random library? I tried to rewrite it using the older code which worked perfectly, but it still had the same error messages.
Aucun commentaire:
Enregistrer un commentaire