【问题标题】:Discord Error: Command raised an exception: NameError: name 'message' is not defined in role reactionDiscord 错误:命令引发异常:NameError:角色反应中未定义名称“消息”
【发布时间】:2021-07-04 15:15:15
【问题描述】:

你好我的机器人我放了一个自动角色系统但是当我运行我的代码时它对我说:

NameError: name 'message' is not define

你能帮我吗? 代码:

@client.event
async def on_ready():
    Channel = client.get_channel('829747866360610843')
    Text= "Hey Si Tu Veux Acceder Au Conversations Exclusivement Pour Les Mangas Clique Sur La Réaction ???? !"
    Moji = await message.channel.send(Channel, Text)
    await client.add_reaction(Moji, emoji='????')
@client.event
async def on_reaction_add(reaction, user):
    Channel = client.get_channel('829747866360610843')
    if reaction.message.channel.id != Channel:
        return
    if user.reaction.emoji == "????":
        Role = discord.utils.get(user.server.roles, name="manga")
        await client.add_roles(user, Role)

【问题讨论】:

  • 这个方法已经过时了,只能从另一个post复制过去。即使错误是不言自明的,也请给我们完整的回溯。

标签: discord.py


【解决方案1】:

错误出现在您的 on_ready 事件中:Moji = await message.channel.send(Channel, Text) 那里没有名为 message 的变量,我的猜测是您正在尝试将消息发送到您之前获得的那个频道,为此,您应该使用Moji = await Channel.send(Text)。 另外:使用 add_reaction 时,建议使用消息中的那个,而不是客户端中的那个:await Moji.add_reaction('?')

【讨论】:

    【解决方案2】:

    谢谢,但他不工作;(

    错误是 Moji = await Channel.send(Text)

    AttributeError: 'NoneType' object has no attribute 'send

    import discord
    from discord.ext import commands
    import random
    from discord import Permissions
    from colorama import Fore, Style
    import asyncio
    
    
    token = "TOKEN"
    
    client = commands.Bot(command_prefix="$")
    
    @client.event
    async def on_ready():
       print(Fore.CYAN + ''' 
       
    RORO EST BOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
     ''')
       await client.change_presence(activity=discord.Game(name="exploser des planètes à la seul force de son coude"))
    
    
    #Latence
    
    @client.event
    async def on_guild_channel_create(channel):
      while True:
        await channel.send(random.choice(SPAM_MESSAGE))
    
    @client.command()
    async def ping(ctx):
        await ctx.message.delete()
        await ctx.send('Pong {0}'.format(round(client.latency, 1)) + 'ms')
    
    
    @client.command()
    async def love(ctx):
        await ctx.message.delete()
        await ctx.send("https://tenor.com/8pZh.gif")
    
    
    @client.command()
    async def goulag(ctx):
        await ctx.message.delete()
        await ctx.send ("https://tenor.com/view/of-to-gulag-gif-19230867")
    
    
    @client.command()
    @commands.has_role("Modération")
    async def kick(ctx, member: discord.Member, *, reason=None):
        await member.kick(reason=reason)
        await ctx.send(f'{member} a bien été exclu')
    
    
    @client.command(pass_context=True)
    async def say(ctx, *, text):
        message = ctx.message
        await message.delete()
        await ctx.send(f"{text}")
    
    
    @client.command()
    async def reverse(ctx):
        await ctx.message.delete()
        await ctx.send("https://tenor.com/bhXgQ.gif")
    
    
    @client.event
    async def on_ready():
        Channel = client.get_channel('829747866360610843')
        Text= "Hey Si Tu Veux Acceder Au Conversations Exclusivement Pour Les Mangas Clique Sur La Réaction ? !"
        Moji = await Channel.send(Text)
        await Moji.add_reaction('?')
    @client.event
    async def on_reaction_add(reaction, user):
        Channel = client.get_channel('829747866360610843')
        if reaction.message.channel.id != Channel:
            return
        if user.reaction.emoji == "?":
            Role = discord.utils.get(user.server.roles, name="manga")
            await client.add_roles(user, Role)
    
    
    client.run(token, bot=True)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-05
      • 1970-01-01
      • 1970-01-01
      • 2016-01-09
      • 2021-11-14
      • 1970-01-01
      相关资源
      最近更新 更多