Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我的discord需要帮助。py bot在discord中_Python_Python 3.x_Discord_Discord.py_Bots - Fatal编程技术网

Python 我的discord需要帮助。py bot在discord中

Python 我的discord需要帮助。py bot在discord中,python,python-3.x,discord,discord.py,bots,Python,Python 3.x,Discord,Discord.py,Bots,我是python和discord.py的初学者,我需要帮助 当我键入“@firstPythonProject时,我想让我的机器人说些什么?Bot#4320说(您希望Bot说的消息)但代码有错误 C:\Users\Arshdeep Singh\Desktop\firstPythonProject_ Bot>python bot.py Logged on as firstPythonProject? Bot#4320 firstPythonProject? Bot#4320 has conne

我是python和discord.py的初学者,我需要帮助

当我键入
“@firstPythonProject时,我想让我的机器人说些什么?Bot#4320说(您希望Bot说的消息)
但代码有错误

C:\Users\Arshdeep Singh\Desktop\firstPythonProject_ Bot>python bot.py
Logged on as firstPythonProject? Bot#4320
firstPythonProject? Bot#4320 has connected to Discord!
Ignoring exception in on_message
Traceback (most recent call last):
  File "C:\Users\Arshdeep Singh\AppData\Roaming\Python\Python39\site-packages\discord\client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "C:\Users\Arshdeep Singh\Desktop\firstPythonProject_ Bot\bot.py", line 28, in on_message
    mention = f'<@!{bot.user.id}>'
NameError: name 'bot' is not defined
Ignoring exception in on_message
Traceback (most recent call last):
  File "C:\Users\Arshdeep Singh\AppData\Roaming\Python\Python39\site-packages\discord\client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "C:\Users\Arshdeep Singh\Desktop\firstPythonProject_ Bot\bot.py", line 28, in on_message
    mention = f'<@!{bot.user.id}>'
NameError: name 'bot' is not defined
Ignoring exception in on_message
Traceback (most recent call last):
  File "C:\Users\Arshdeep Singh\AppData\Roaming\Python\Python39\site-packages\discord\client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "C:\Users\Arshdeep Singh\Desktop\firstPythonProject_ Bot\bot.py", line 28, in on_message
    mention = f'<@!{bot.user.id}>'
NameError: name 'bot' is not defined
Ignoring exception in on_message
Traceback (most recent call last):
  File "C:\Users\Arshdeep Singh\AppData\Roaming\Python\Python39\site-packages\discord\client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "C:\Users\Arshdeep Singh\Desktop\firstPythonProject_ Bot\bot.py", line 28, in on_message
    mention = f'<@!{bot.user.id}>'
NameError: name 'bot' is not defined
Ignoring exception in on_message
Traceback (most recent call last):
  File "C:\Users\Arshdeep Singh\AppData\Roaming\Python\Python39\site-packages\discord\client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "C:\Users\Arshdeep Singh\Desktop\firstPythonProject_ Bot\bot.py", line 28, in on_message
    mention = f'<@!{bot.user.id}>'
NameError: name 'bot' is not defined
C:\Users\Arshdeep Singh\Desktop\firstPythonProject\ubot>pythonbot.py
作为FirstPython项目登录?机器人#4320
第一个python项目?机器人4320已经连接到了Discord!
忽略on_消息中的异常
回溯(最近一次呼叫最后一次):
文件“C:\Users\Arshdeep Singh\AppData\Roaming\Python\Python39\site packages\discord\client.py”,第343行,在运行事件中
等待coro(*args,**kwargs)
文件“C:\Users\Arshdeep Singh\Desktop\firstPythonProject\ubot\Bot.py”,第28行,在on_消息中
提及
NameError:未定义名称“bot”
忽略on_消息中的异常
回溯(最近一次呼叫最后一次):
文件“C:\Users\Arshdeep Singh\AppData\Roaming\Python\Python39\site packages\discord\client.py”,第343行,在运行事件中
等待coro(*args,**kwargs)
文件“C:\Users\Arshdeep Singh\Desktop\firstPythonProject\ubot\Bot.py”,第28行,在on_消息中
提及
NameError:未定义名称“bot”
忽略on_消息中的异常
回溯(最近一次呼叫最后一次):
文件“C:\Users\Arshdeep Singh\AppData\Roaming\Python\Python39\site packages\discord\client.py”,第343行,在运行事件中
等待coro(*args,**kwargs)
文件“C:\Users\Arshdeep Singh\Desktop\firstPythonProject\ubot\Bot.py”,第28行,在on_消息中
提及
NameError:未定义名称“bot”
忽略on_消息中的异常
回溯(最近一次呼叫最后一次):
文件“C:\Users\Arshdeep Singh\AppData\Roaming\Python\Python39\site packages\discord\client.py”,第343行,在运行事件中
等待coro(*args,**kwargs)
文件“C:\Users\Arshdeep Singh\Desktop\firstPythonProject\ubot\Bot.py”,第28行,在on_消息中
提及
NameError:未定义名称“bot”
忽略on_消息中的异常
回溯(最近一次呼叫最后一次):
文件“C:\Users\Arshdeep Singh\AppData\Roaming\Python\Python39\site packages\discord\client.py”,第343行,在运行事件中
等待coro(*args,**kwargs)
文件“C:\Users\Arshdeep Singh\Desktop\firstPythonProject\ubot\Bot.py”,第28行,在on_消息中
提及
NameError:未定义名称“bot”
请帮我修一下这个

#代码
#机器人
随机输入
进口不和
导入时间
client=discord.client()
类MyClient(discord.Client):
异步def on_就绪(自):
打印('登录身份',self.user)
打印(f{client.user}已连接到Discord!')
_消息上的异步定义(self,message):
#不要回应我们自己
如果message.author==self.user:
返回
如果message.content==“ping”:
等待消息.channel.send('pong')
如果message.content.lower()
wait message.channel.send('yes pog')
如果message.content.lower()中的“rickroll”或message.content.lower()中的“rick roll”:
等待消息。删除()
wait message.channel.send(f'{message.author.ention},不错)
提及
如果在message.content中提及:
如果message.content中的“{antify}say”:
sayOutput=message.content.replace(“{提及}说”,message.content)
wait message.channel.send(f'{message.author.ention}要求我说:\n',
(输出)
client=MyClient()
client.run('no token 4 u(no its不是因为无效的token其他命令工作)'))
有人能帮我吗? 我有问题,不明白o.o Rick Astley的感谢


关于我为什么和如何修复大部分代码,我想你应该提到作者。只需将
bot.user.id
替换为
message.author
。没有bot变量,因此您将主要引用消息或频道。

提及=f'
此部分会导致错误。您尚未定义bot变量。如何定义bot变量?@marmeladze请帮助?如何定义机器人变量?我不知道。提供有关
bot
的更多线索。也许您只需要
message.user.id
而不是
bot.user.id
您的bot实例被称为
client
,而不是
bot
。将
bot.user.id
替换为
client.user.id
,您应该很好