AttributeError: 模块 ‘discord’ 没有 ‘interaction’ 属性。

huangapple go评论54阅读模式
英文:

AttributeError: module 'discord' has no attribute 'interaction'

问题

discord.py没有"interaction"属性,这是我新的Discord机器人需要的。

这是我的代码:

@bot.tree.command(name="help")
async def help(interaction: discord.interaction):
    await interaction.response.send_message("Hey, das ist ein Test")

我尝试过,但出现了"AttributeError: module 'discord' has no attribute 'interaction'"的错误。

英文:

discord.py has not the attribute "interaction", which i need for my new discord bot.

This is my code:

@bot.tree.command(name="help")
async def help(interaction: discord.interaction):
    await interaction.response.send_message(f"Hey, das ist ein test")

I tried "AttributeError: module 'discord' has no attribute 'interaction'"

答案1

得分: 4

那应该是 discord.Interaction,而不是 discord.interaction。确保使用大写的 I这里 是相关的 API 文档链接。

英文:

That would be discord.Interaction, not discord.interaction. Make sure you are using a capital I. Here is the link to the relevant API docs.

答案2

得分: 0

After reviewing your code, it looks like you're missing a capital I in discord.Interaction. However, if it still doesn't work after modifications made, consider looking at the version of discord.py you are using. Maybe it is not the 2.0.0 (minimum).

And if it is the right version, try using this way of making it:

#imports

intents = discord.Intents.all() # defining intents
intents.members = True

bot = discord.AutoShardedClient(intents = intents, shard_count = 1) # Making a new bot
slash = app_commands.CommandTree(bot) # Declaring commandTree

@slash.command(name="help")
async def help(interaction: discord.Interaction):
    await interaction.response.send_message("Hey, das ist ein test")
英文:

After reviewing your code, it looks like you're missing a capital I in discord.Interaction.
However, if it still doesn't work after modifications made, consider looking at the version of discord.py you are using. Maybe it is not the 2.0.0 (minimum)

And if it is the right version, try using this way of making it:

#imports

intents = discord.Intents.all() # defining intents
intents.members = True

bot = discord.AutoShardedClient(intents = intents, shard_count = 1) # Making a new bot
slash = app_commands.CommandTree(bot) # Declaring commandTree

@slash.command(name = "help")
async def help(interaction: discord.Interaction):
    await interaction.response.send_message(f"Hey, das ist ein test")

huangapple
  • 本文由 发表于 2023年5月14日 04:20:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/76244714.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定