Discord 错误:命令引发异常:NameError:角色反应中未定义名称“消息”

时间:2021-04-08 17:46:12

标签: discord.py

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

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)

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

谢谢,但他不工作;(

错误是 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)
相关问题